PHP APC - make your app super fast!

One of the many advantages of using Ubuntu over windows is the ability to install and test out all the plug-ins available for PHP. One of them being APC (Alternative PHP Cache).

I just upgraded to the latest Ubuntu 10.10 and figured I would take a quick screen shot, for anyone that is doubting how much something like APC can affect an application. When I first found out about them, I did not think the effects would be so large. This is just a clean install of PHP and MySql from Ubuntu's 'apt-get install' command. I have not done any extra tweaking after installing APC, just a simple restart of Apache.

  

As you can see memory usage is half, and the request time is 2/3's what it was. And this was just by typing 2 commands into a shell. 'sudo apt-get install php-apc' and 'sudo service apache2 restart'. About 30 seconds out your day and save your self hours on waiting for pages to load.

Simply put, APC works by caching the compiled PHP source code and saving it in memory. This saves the server from having to read code off the disc and compiling the code for each and every request. Having the compiled code served from memory saves a lot of time by limiting slow disk reads for PHP files.

When using APC with CakePHP you do not need to use the APC cache settings to see these gains as the big speed comes from caching the compiled code. What the CakePHP APC config will do is save your cached data to memory instead of the files it uses by default, again saving on disk reads.

on 3/11/10

Nice article. Just a note though, on the comment you posted on my blog a little while ago (concerning the CakePHP Script Combiner helper). It's now available on Github, as you requested :)