PHP Acceleration through Caching
The PHP scripting language is very flexible and gives a lot of bang for the buck. However, it is often criticized by supporters of J2EE and other web development platforms for not scaling well. Nevertheless, we see plenty of large sites running on PHP as well as popular applications like Vbulletin.
Whenever a PHP script is run, mod_php or a php binary in CGI mode parses the script and spits the output to the web server to send along to the web browser. Basically, the php code is “compiled” on the fly. This works great until we start getting traffic to our site and have to compile the same code over, and over, and over again. Imagine having to compile an everyday program like Microsoft Office each time you load it - loading is already slow enough as it is! A PHP-driven site with lots of dynamic content will easy chew up the server’s CPU resources once the traffic hits hard enough.
Some advanced PHP applications use caching at the application level, such as Wordpress which now has some caching features. But what do you do when you have a large custom-written PHP content management system based on a sport that is now getting worldwide attention and traffic? That is the situation one of our customers was in recently. We implemented eAccelerator, an open-source project that implements caching in the PHP scripting engine. Their website explains that it “increases the performance of PHP scripts by caching them in their compiled state, so that the overhead of compiling is almost completely eliminated.”
Sure enough, eAccelerator worked as advertised. It cut the CPU usage on this particular server in half.