PHP APC – Alternative PHP cache – Part 1


Looking for a quick win with taking some of the pressure off of your webservers??

This could be one for you. The Alternative PHP Cache is really quick and simple to install. Because of the way it caches, you should see no issues with using this one a site with dynamic content.

Its straight forward to install this using the PEAR PECL installer:

from the commandline   $>pecl install apc

this will install APC, but to be able to see all the nice performance statistics you have to compile and make the source version to allow you to grab the apc.php file. – I did this on a non production local box.

grab the latest one here

then:  $> tar zxvf APC-3.1.6.tgz

$>cd APC-3.1.6

$>./configure –with-php-config=/usr/local/php/bin/php-config

Now take a look in the current working directory and you will see that apc.php has appeared. You can now move this to wherever you want to serve the graphs from on your production server. For a quick test you can just put it in your default webroot.

Next up you need to put the following entry in your php.ini file:

To see this working ‘out-of-the-box’ you should just be able to run apachectl restart, and check the PHP extensions to see if APC is running. You can do this using phpinfo(); inside a php file inside your webroot or from the commandline run: php -i|grep apc

If you decide after running the cache a bit and seeing how frequently the cache is being filled/purged you might want to increase the amount of memory you are giving to the cache, you can do this by adding a line like the following to the php.ini file


This will make the cache 128M in size the next time that apache is restarted. Bear in mind that you need to have enough free resources on your box to adjust this value.

Now to see the graphing information you will need to edit apc.php and change the default user and password that is listed in the top of the file, then when you access apc.php you will get presented with a .htaccess style user/passwd  dialog box. Put the user and password you entered in the apc.php file here. Next you should see a load of great stats on how well the cache is optimizing your site. You can also see which frequently accessed pages it is cachind and the amount of total cache hits/misses,etc.

Theres loads more to this tool, which I will follow up on next time. But this should be enough to see a performance benefit straight away. Enjoy!

Linux Guru & Technology Enthusiast…