A Practical Guide to Data Caching with Zend Server

April 15, 2009


Did you know that Zend Server not only has it’s own PHP accelerator built in (like APC). But that it also has similar functionality allowing for caching of data in shared memory? “Shahar Evron”:http://prematureoptimization.org/, Project Manager of Zend Server, has written a white paper describing just how exactly to use this to good effect. You can “download this whitepaper as a PDF”:http://static.zend.com/topics/Zend-Server-Data-Caching-Whitepaper-0106-T-WP-R1-EN.pdf

bq. When asked about the most significant methods to speed up PHP applications, most experts would say “Cache, Cache and Cache”. There are a lot of optimizations that could be done to PHP code that would make it run faster, but the most effective method to speed up PHP execution is to simply execute less, and one of the best ways to achieve that is through caching. Zend Server provides several caching-related features, including Optimizer+ for byte-code caching, full-page caching using Zend Page Cache, and the Data Cache API.

It should be noted that Optimizer+ (The accelerator and byte-code-cache), and Zend Data Cache (The shared memory caching mechanism similar to APC User Variables) are available in both Zend Server, and Zend Server CE. The Page Cache is a functionality that only comes with a paid subscription to Zend Server.

3 Responses to “A Practical Guide to Data Caching with Zend Server”

  1. argtrooper Says:

    Exelent paper! very usefull.

    But i have one question, I’m implementing a web app that runs CLI process on background (on windows). I need to share data between CLI process and the web app.

    I implement this using: zend_disk_cache_store, zend_disk_cache_fetch
    This functions works perfect on web app (I could Store and read data) but on CLI process do not work at all even if a store some data and try to read it in the same CLI process.

    On CLI this didnt work:
    if (zend_disk_cache_store("valor","Hola!!!!",3600) === false) error_log("Error on CLI");

    I use this to start the CLI process:

    if (substr(PHP_OS, 0, 3) == ‘WIN’) {
    $this->proc = popen(‘start /b php "’ . $this->path . ‘\\’ . $this->file . ‘" ‘ . $this->args, ‘r’);
    } else {
    $this->proc = popen(‘php ‘ . $this->path . ‘/’ . $this->file . ‘ ‘ . $this->args . ‘ &’, ‘r’);

    Any clue?


  2. shahar Says:


    Thanks for reporting – that’s indeed a typo and should say ‘false’ instead of NULL.

    A fixed version of the document will be uploaded soon.


  3. aarrowood Says:

    I have followed the code in the examples and found that a failed zend_shm_cache_fetch() does not return a NULL, but, as the Zend Server documentation states, a FALSE value.

    So, as in the whitepaper, instead of,

    $recentPosts = zend_shm_cache_fetch(‘recentposts’);
    if ($recentPosts === null) {


    $recentPosts = zend_shm_cache_fetch(‘recentposts’);
    if ($recentPosts === false) {

    Using ‘=== false’ for checking zend_shm_cache_fetch() cache results works for me, where ‘=== null’ does not.

    -Adam A