Staex
Staex

Reputation: 31

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 ?

Upvotes: 3

Views: 324

Answers (1)

Zdenek Machek
Zdenek Machek

Reputation: 1744

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

Upvotes: 1

Related Questions