Linux.com

Home Linux Community Community Blogs General Linux Alternative PHP Cache - quick win for webserver optimization

Alternative PHP Cache - quick win for webserver optimization

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 http://pecl.php.net/get/APC-3.1.6.tgz

then:  $> tar zxvf APC-3.1.6.tgz

$>cd APC-3.1.6

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

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:

extension=apc.so

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

apc.shm_size=128

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!

 

Comments

Subscribe to Comments Feed

Upcoming Linux Foundation Courses

  1. LFD320 Linux Kernel Internals and Debugging
    04 Aug » 08 Aug - Virtual
    Details
  2. LFD405 Embedded Linux Development with Yocto Project
    04 Aug » 07 Aug - Santa Clara, CA
    Details
  3. LFD312 Developing Applications For Linux
    18 Aug » 22 Aug - Virtual
    Details

View All Upcoming Courses


Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board