Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP performance (Opcode caching / function volatility)

BACKSTORY

I maintain a spectrum of (web-)applications that all use a large homegrown PHP library. Some of these applications are traditional desktop applications that are used by employees, but others (which are also more relevant to this question), are PHP websites for which performance is becoming a more important issue as the popularity continues to grow.

CURRENT PHP CACHING METHODS

To speed up one of our websites (it's a shop, think of it as thinkgeek.com), i employ memcached to cache certain segments of the website that don't require constantly being dynamicly build (such as the product listing for a certain category).

We also use a pretty much factory-default installation of APC as an OPCode cache.

Both of these methods bring significant improvements to the website's performance, but i'm very much looking to go further down the road of optimisation.

Function Volatility in PHP

Coming from a Database background myself, i'm very fond of how PostgreSQL for example, uses function volatility to get massive performance gains while maintaining reliable and accurate results.

My question is, is there any extension to PHP that allows the developer to mark certain functions (or class methods) as IMMUTABLE? (meaning the result of that function is always the same, when given the same input arguments). This caching extension could then cache the result of that function which should result in massive performance gains when using big libraries of code.

A simple example would be a method such as SomeClass::getWebsiteFooter(); which returns some HTML code that's always the same, unless the website has been altered (in which case the cache would be flushed).

Does something like this exist ? I haven't been able to find anything remotely similar on the market. Are there any other methods of performance improvement that might benefit my situation ?

like image 291
Staex Avatar asked Aug 05 '26 12:08

Staex


1 Answers

I would say you have look at php application as a web application and implement several levels of caching.

IMMUTABLE methods - I don't think is good approach. Usage of caching on db level, application level (memcached) is good start.

Then I would suggest caching on view level Smarty caching and caching proxy like Squid or Varnish

like image 83
Zdenek Machek Avatar answered Aug 07 '26 00:08

Zdenek Machek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!