PHP Caching Solutions: Best of the Pack

November 23rd, 2011 Leave a comment
Like the article?

Site performance versus traffic: it is a tough battle to fight. When working with PHP applications we usually have to face this issue sooner or later, as a site becomes more popular it can begin to suffer from performance issues. There are several ways that you can improve your site’s performance to help solve this problem, but one of the easiest ways is to set up PHP caching.

PHP Caching is an excellent solution for Web sites that wish to improve their site performance by allowing their dynamic pages to be stored client-side by your application. These solutions basically work around the idea that you can cache your complied PHP scripts, cutting down on the amount of time it can take your server to do the same processing over and over to re-compile and serve the page. This article will discuss some of the PHP Caching solutions available and highlight which ones have the best features for you.

Alternative PHP Cache (APC)

Alternative PHP Cache (APC)

Alternative PHP Cache is an open-source solution that has been in production since 2003 and has swiftly become the popular turn-key solution to PHP Caching. It has been given PHP’s endorsement and will be included built-in to core PHP builds beginning with version 5.4. APC is maintained by a team of a dozen developers that work on all aspects of the project. It was originally designed to provide a free and open way to optimize PHP intermediate code and provide a robust framework for caching, and it does a great job of it.

APC is an excellent choice for any site owner that wants to get the most out of their PHP scripts. It is also currently available on all platforms that you can install PHP on so there should be no problem getting in to your system. The bonus with APC is after 5.4 you won’t even have to install it since it will already be built into the core. Once you have PHP installed (or updated) you can simply turn it on and configure.

We are using APC on as a standard “opcode” cache as well as together with the WordPress W3 Total Cache plugin, as a database query and PHP object cache to speed up commonly used operations.

If you already ARE using APC on your site, here an excellent article by Chris Gilligan on how to tune your APC configuration: How to Configure APC Cache on Virtual Servers with PHP running under FCGId.

Zend Optimizer+

Zend Server

Zend Optimizer+ is a component of Zend Server or Zend Server Community Edition, developed by Zend. Previously called Zend Cache and Zend Accelerator, Zend provides many PHP development solutions from an IDE to testing, servers and bug management. The Zend Optimizer+ helps speed up your PHP script execution time by caching with opcode and using other tricks with optimization. Zend stores PHP files as pre-compiled script bytecode and takes advantage of shared memory which can eliminate having to read the scripts from disk.

Unfortunately you cannot purchase Zend Optimizer+ on its own and it must be purchased with the server. However it is a strong contender for our Best of the Pack due to its robust architecture and many advantages. If you have the money to spend, it is worth taking a look at the Zend Platform.

Zend Guard and Zend Optimizer

Zend Guard

Not to be confused with the Zend Optimizer+, Zend Optimizer is a free distribution from Zend that will run and optimize files encoded with Zend Guard. The Zend Guard application, also a free download, allows you to encode your PHP files to keep their secure while distributing them or while they are in-use on your server. This is a great way to get the benefits of the Zend system while increasing the performance of your PHP applications for no out-of-pocket costs. All of the Zend products are currently available for Linux, Windows or Mac OS X.



XCache is an open-source caching solution developed by Lighttpd. It is touted as a fast and stable solution that is able to handle high-load servers. You can run it under Linux, FreeBSD and Windows and it supports thread-safe and non-thread safe versions of PHP up to the latest stable PHP release. There are many advantages to running XCache, such as:

  • Code is optimized and are made into opcode caches
  • C Code is produced via a generator that make it harder for human error to disrupt the system
  • Coverager – a real-life test case framework that allows you to test and control scripts with a real browser
  • Built-in checks so that the cache cannot become corrupted
  • Administrator script allows you to perform various tasks as well as view statistics

XCache is given a thumb-up for being light-weight as well as robust. Lighttpd has developed a caching solution with their opcode system and it is definitely worth a consideration for your server needs.

As you can see there are several options to choose from when deciding on a PHP caching solution. When deciding which one is right for you, take into account the amount of traffic your server will be receiving, your server operating system and what kind of access will be needed to install your solution. This last step is especially important if you are working with a hosting provider that may not allow console access for installs. Remember that there is no “one size fits all” solution so make sure you check out all of the angles before you commit. I am sure your Web site performance will thank you!

Help us spread the word!
  • Twitter
  • Facebook
  • LinkedIn
  • Pinterest
  • Delicious
  • DZone
  • Reddit
  • Sphinn
  • StumbleUpon
  • Google Plus
  • RSS
  • Email
  • Print
Don't miss another post! Receive updates via email!