I have a number of personal sites that I maintain, three of which (including this site) make use of the Wordpress publishing platform to manage blogs, and all fundamentally powered by PHP. The sites are all hosted on the same low-cost (and therefore low-power) VPS slice that also manages a number of other services for me, so it is therefore important that the PHP web applications operate as efficiently as possible to make best use of the limited resources available.
I have been doing some optimisation work on the Wordpress managed sites recently and decided it was time to trial a PHP cache on the server.
PHP is an interpreted language, so each and every time a PHP page is requested the server must read in the (sometimes numerous) files required and compile them into executable code. PHP caches save this compiled code in the server’s memory, so that when the file is requested again the compilation step can be skipped and the page delivered much faster. Enabling caching can reduce the time it takes to generate a page by up to 90%.
There are a number of packages in this space but my research indicated that they are roughly equivalent in function and performance (now there’s a contentious statement). XCache was readily available as a binary package for my VPS’ operating system and so it was duly installed. I installed the provided XCache Admin web pages as a separate virtual host and password protected the pages, then restarted the web server to pick up the changes.
After some initial experimentation I settled on the following XCache configuration:
# configuration for php xcache module extension=xcache.so # administration xcache.admin.user = "" xcache.admin.pass = "" xcache.admin.enable_auth = Off xcache.test = Off xcache.coredump_directory = "" # cacher xcache.cacher = On xcache.size = 64M xcache.count = 1 xcache.slots = 8K xcache.ttl = 3600 xcache.gc_interval = 300 xcache.var_size = 1M xcache.var_count = 1 xcache.var_slots = 8K xcache.var_ttl = 3600 xcache.var_maxttl = 0 xcache.var_gc_interval = 300 xcache.readonly_protection = Off xcache.mmap_path = "/dev/zero" # optimiser xcache.optimizer = Off # coverager xcache.coverager = Off xcache.coveragedump_directory = "/tmp/pcov/"
The above configures a 64Mb PHP opcode cache and a 1Mb variable cache. Objects in both caches expire after one hour and garbage collection is run every five minutes.
With the XCache module in place and correct cache operation confirmed, I ran a number of benchmarks on my Wordpress sites using the Siege load testing and benchmarking utility. The results were as follows:
Cache disabled:
# siege -b -c 10 -r 25 http://www.rainmiles.com/ ** SIEGE 2.66 ** Preparing 10 concurrent users for battle. The server is now under siege.. done. Transactions: 250 hits Availability: 100.00 % Elapsed time: 42.22 secs Data transferred: 1.70 MB Response time: 1.58 secs Transaction rate: 5.92 trans/sec Throughput: 0.04 MB/sec Concurrency: 9.37 Successful transactions: 250 Failed transactions: 0 Longest transaction: 5.01 Shortest transaction: 0.28
Cache enabled:
# siege -b -c 10 -r 25 http://www.rainmiles.com/ ** SIEGE 2.66 ** Preparing 10 concurrent users for battle. The server is now under siege.. done. Transactions: 250 hits Availability: 100.00 % Elapsed time: 22.17 secs Data transferred: 1.70 MB Response time: 0.85 secs Transaction rate: 11.28 trans/sec Throughput: 0.08 MB/sec Concurrency: 9.64 Successful transactions: 250 Failed transactions: 0 Longest transaction: 3.42 Shortest transaction: 0.15
I know these are quick and not particularly well designed benchmarks, but they serve well enough to illustrate my point.
The key figure here is Transaction Rate, which increased from 5.92 to 11.28 transactions per second with the cache enabled. Implementing XCache therefore gave a 90% speedup in the overall throughput of Wordpress generated pages, but of course this metric includes database and other processing so the actual boost to the PHP generation process would be in excess of this figure.
Installing XCache took less than an hour and almost doubled the speed of my Wordpress blogs and the other PHP powered sites on the server. I’m not aware of any problems caused by the use of a caching layer and the sites appear to be operating normally. I’m left wondering why I didn’t do it earlier.
Do you have any experiences with XCache or other caches, good or bad? Share them in the comments below!

