Open main menu

A PHP Acelerator is a tool that will enhance the performance of web applications written for the PHP scripting language. The free Alternative PHP Cache (APC) is distributed as a PEAR package.

If you run your own LAMP server with PHP applications, then please install it. The Moodle documentation includes information on setting up APC; including testing before and after performance with "Apache Bench"

Installation

Assuming you already have Apache2 and PHP5 (with dev extensions so PECL can run phpize), it's as easy as

# make sure we have the development headers and apxs2 binary for threaded versions of apache2
sudo apt-get install apache2-threaded-dev
# install the APC extension
sudo pecl install APC
# pecl would have updated my php.ini file automatically, but it did not know where to look.
# set it for future reference
sudo pear config-set php_ini /etc/php5/apache2/php.ini
# do the configuration of php settings file myself
sudo vi /etc/php5/apache2/php.ini
# test and restart apache
sudo apache2ctl configtest
sudo apache2ctl graceful
# make a symbolic link to the system front-end
cd /var/www
sudo ln -s /usr/share/php/apc.php

MediaWiki

MediaWiki can take advantage of the APC cache if you tell it to. see The Manual for cache settings, and set mw:Manual:$wgMainCacheType in LocalSettings.php:

$wgMainCacheType = CACHE_ACCEL;

Troubleshooting

If you notice sluggishness in your site after installing APC, then check out the front-end (apc.php). The sure sign that you need to increase your cache size is that the "cache full" count is greater than one.

Cache is too small
  1. Check your memory
  2. Increase the Shared Memory Size for APC in your php.ini file e.g. apc.shm_size = 128
  3. Restart Apache
  4. Use the Apache Bench tool to test performance with and without APC enabled.

Notes

APC, aside from speeding up your website, also provides a storage mechanism outside the traditional cookie/session mechanism. So, you could set an application variable or constant and (assuming that the cache is not cleared, etc.) retrieve that value from another context.