Zend Cache Review

This week we will cover the Zend Cache, A script caching mechanism from Zend which will save pre-compiled versions of PHP scripts in order to avoid having to re-compile them every time, resulting in huge performance benefits. First we will go over the strengths and weaknesses of Zend’s Cache and then we will move onto comparing the Zend Cache to other, open-source, free cache’s.

A couple of weeks ago, Zend finally released their long awaited product line, including much needed products, such as a stable, quality Cache as well as an encoder that allows you to encrypt and distribute your code. But are these products all that they’re hyped to be? Are they worth their price tags? Over the next couple of weeks I will be offering you my reviews of the different Zend products, the Zend Launchpad, the Zend IDE, the Zend Cache and the Zend encoder.

This week we will cover the Zend Cache, A script caching mechanism from Zend which will save pre-compiled versions of PHP scripts in order to avoid having to re-compile them every time, resulting in huge performance benefits. First we will go over the strengths and weaknesses of Zend’s Cache and then we will move onto comparing the Zend Cache to other, open-source, free cache’s.

{mospagebreak title=Introduction} A couple of weeks ago, Zend finally released their long awaited product line, including much needed products, such as a stable, quality Cache as well as an encoder that allows you to encrypt and distribute your code. But are these products all that they’re hyped to be? Are they worth their price tags? Over the next couple of weeks I will be offering you my reviews of the different Zend products, the Zend Launchpad, the Zend IDE, the Zend Cache and the Zend encoder.

This week we will cover the Zend Cache, A script caching mechanism from Zend which will save pre-compiled versions of PHP scripts in order to avoid having to re-compile them every time, resulting in huge performance benefits. First we will go over the strengths and weaknesses of Zend’s Cache and then we will move onto comparing the Zend Cache to other, open-source, free cache’s.

{mospagebreak title=Overview} Note: This is an educated guess at how the Cache works based on the way the two open source cache’s work and some of Zend’s online documentation.

To understand how the Zend cache works, it is first important to understand how the Zend engine (the scripting engine that powers PHP 4) works. What the Zend engine does (in a very basic sense), is given a PHP file, parses it, and builds a complex data structure based on the php file given to it (known as an op structure). Then it goes through this op structure, and executes it, performing the various calls (such as database connections, etc.) and functions defined by the op structure.

What the Zend Cache does is eliminates the need for the Zend engine to constantly re-compile (parse the php file into an op structure) a php file, by storing the compiled results either in shared memory or in mmap’d files (beyond the scope of this article, for more information “man mmap”). As file size and script complexity increases, this leads to significant speed increases.

In addition to cache’ing the compiled version of the script, the Zend Cache performs certain execution optimizations on the code (not present in its competitors), cutting down on the execution time of the program as well. This added bonus is a really nice feature, and probably a major contributor to the blazing speed the cache provides (note that this feature alone is available with the Zend Optimizer, a free product from Zend).

The Zend Cache also includes an online interface which allows you to set configuration options such as how much memory the cache uses or whether or not to validate the timestamps of the files being cached. This online interface also provides a plethora of other information which can help you cut the speed of your applications. Some of these include cache activity, a list of most requested scripts, most memory intensive scripts, etc. You can view an online demo, at http://www.zend.com/cguidemo/.

{mospagebreak title=Overview} Note: This is an educated guess at how the Cache works based on the way the two open source cache’s work and some of Zend’s online documentation.

To understand how the Zend cache works, it is first important to understand how the Zend engine (the scripting engine that powers PHP 4) works. What the Zend engine does (in a very basic sense), is given a PHP file, parses it, and builds a complex data structure based on the php file given to it (known as an op structure). Then it goes through this op structure, and executes it, performing the various calls (such as database connections, etc.) and functions defined by the op structure.

What the Zend Cache does is eliminates the need for the Zend engine to constantly re-compile (parse the php file into an op structure) a php file, by storing the compiled results either in shared memory or in mmap’d files (beyond the scope of this article, for more information “man mmap”). As file size and script complexity increases, this leads to significant speed increases.

In addition to cache’ing the compiled version of the script, the Zend Cache performs certain execution optimizations on the code (not present in its competitors), cutting down on the execution time of the program as well. This added bonus is a really nice feature, and probably a major contributor to the blazing speed the cache provides (note that this feature alone is available with the Zend Optimizer, a free product from Zend).

The Zend Cache also includes an online interface which allows you to set configuration options such as how much memory the cache uses or whether or not to validate the timestamps of the files being cached. This online interface also provides a plethora of other information which can help you cut the speed of your applications. Some of these include cache activity, a list of most requested scripts, most memory intensive scripts, etc. You can view an online demo, at http://www.zend.com/cguidemo/.

{mospagebreak title=What’s the increase?} When it comes to a product such as the Zend Cache its hard to measure an actual speed increase the end user will receive, because it depends on the type of script is being run. When running an extremely long script (many lines of code), with little in the way of execution time (database transactions, socket access, etc.) than the Zend Cache can increase the performance of your script by tenfold. However, if you spend a lot of time in the execution phase, then the cache will still improve the speed of your scripts, but the increase will not be as signifigant.

Still, I ran some “un-official” tests on my laptop (PIII 733 MHz, 128mb ram, Linux, Apache, PHP, Zend Cache, MySQL), on a variety of scripts, some which would be taxing as far as execution time was concerned and not so heavy in regards to compile time, and some which were taxing on compile time, but required very little in the way of execution time and then some which were a balance between the two. Overall, I found out that the Zend Cache provided an average increase in the speed of my scripts of 63.43%. Which I found to be a quite acceptable speed increase, considering that some of the scripts I tested were almost purely execution time. In fact I’d wager that on most systems with larger scripts, you should be seeing something like a 100 – 200 % speed increase when using the Zend Cache (maybe more!)

{mospagebreak title=What’s the increase?} When it comes to a product such as the Zend Cache its hard to measure an actual speed increase the end user will receive, because it depends on the type of script is being run. When running an extremely long script (many lines of code), with little in the way of execution time (database transactions, socket access, etc.) than the Zend Cache can increase the performance of your script by tenfold. However, if you spend a lot of time in the execution phase, then the cache will still improve the speed of your scripts, but the increase will not be as signifigant.

Still, I ran some “un-official” tests on my laptop (PIII 733 MHz, 128mb ram, Linux, Apache, PHP, Zend Cache, MySQL), on a variety of scripts, some which would be taxing as far as execution time was concerned and not so heavy in regards to compile time, and some which were taxing on compile time, but required very little in the way of execution time and then some which were a balance between the two. Overall, I found out that the Zend Cache provided an average increase in the speed of my scripts of 63.43%. Which I found to be a quite acceptable speed increase, considering that some of the scripts I tested were almost purely execution time. In fact I’d wager that on most systems with larger scripts, you should be seeing something like a 100 – 200 % speed increase when using the Zend Cache (maybe more!)

{mospagebreak title=Competition} The Zend Cache is not the only option, there also happens to be two other open source (got to respect the open source) cache’s. The first being the APC (Alternative PHP Cache), http://apc.communityconnect.com/, which is a high quality, stable, open source cache. The second is the AfterBurner cache, http://bwcache.bware.it/, which while still young, shows some promise.

At this point the only real competitor to the Zend Cache, is the APC, which offers a similar functionality set to that of the Zend Cache’s. On tests, however, the APC turned out to be much slower than Zend’s Cache, yielding an average performance increase of only 30.31%, less than half that of Zend’s Cache (still on larger scripts I’d expect this to turn into a 60% performance increase).

Even the APC might not be as good as the Zend Cache, there is something to be said for free software. The Zend Cache comes with quite a hefty price tag. A price tag which might not be affordable for smaller businesses or freelance web developers. The APC is perfect for these users, who probably aren’t creating applications where speed is critical, but would always like a nice boost. Also, because the APC is open, there is no reason why it might not one day be as fast as the Zend Cache.

{mospagebreak title=Competition} The Zend Cache is not the only option, there also happens to be two other open source (got to respect the open source) cache’s. The first being the APC (Alternative PHP Cache), http://apc.communityconnect.com/, which is a high quality, stable, open source cache. The second is the AfterBurner cache, http://bwcache.bware.it/, which while still young, shows some promise.

At this point the only real competitor to the Zend Cache, is the APC, which offers a similar functionality set to that of the Zend Cache’s. On tests, however, the APC turned out to be much slower than Zend’s Cache, yielding an average performance increase of only 30.31%, less than half that of Zend’s Cache (still on larger scripts I’d expect this to turn into a 60% performance increase).

Even the APC might not be as good as the Zend Cache, there is something to be said for free software. The Zend Cache comes with quite a hefty price tag. A price tag which might not be affordable for smaller businesses or freelance web developers. The APC is perfect for these users, who probably aren’t creating applications where speed is critical, but would always like a nice boost. Also, because the APC is open, there is no reason why it might not one day be as fast as the Zend Cache.

{mospagebreak title=Recommendations} While smaller businesses where speed is not god, may be fine with the APC and happy to avoid the Cache’s hefty price tag, for businesses where speed is critical, its clear that the Zend Cache is the only option. It is a stable, fast, and (editorializing) a very cool product, which is worth its weight in gold.

{mospagebreak title=Recommendations} While smaller businesses where speed is not god, may be fine with the APC and happy to avoid the Cache’s hefty price tag, for businesses where speed is critical, its clear that the Zend Cache is the only option. It is a stable, fast, and (editorializing) a very cool product, which is worth its weight in gold.

[gp-comments width="770" linklove="off" ]

chat