Alternative PHP Cache is an open source framework that optimises and tunes the output of the PHP opcode compiler and stores the compiled result in shared memory. This optimisation leads to faster runtime execution. It maintains a shared memory opcode cache which allows the server to reuse the compiled code rather than going through the task of retrieving source files from disk and recompiling them on every page load
Compiled files remain in the shared memory cache and will be recompiled if the original source code files are updated. For a substantive application consisting of a large source code base such as Drupal, there will be an increase in page generation performance as a result.
APC also provides extra functionality as well as opcode optimisation and caching, such as providing the ability for PHP applications to store and retrieve keyed data stored in shared memory. This provides a caching mechanism allowing applications to cache and significantly speed up access to commonly used data without having to constantly access disk or SQL backends.
APC Shared Memory
To set the shared memory high enough to accomodate the APC cache, using a 256Mb example of ‘apc.shm_size = 256M’
sysctl -w kernel.shmmax=268435456
To permanently adjust shared memory add this line to’/etc/sysctl.conf’.
APC shared memory is a finite resource configured in apc.ini, an indication that APC is not performing optimally is fragmentation.
Busy backend? you could use ‘apc.filters’ to filter in/out PHP files handled by APC, if your regex skills are up to it !!. For a Drupal example to exclude admin files and include only php and inc files
apc.filters = "+inc$,+php$,-admin"
Excluding Drupal contributed modules to cache Drupal core only:
apc.filters = "+inc$,+php$,-admin,-sites/all/modules"
This becomes complicated in the case of an Apache virtual host environment where it may be beneficial to have some hosts handled by APC but not others.
Disable Virtual Host APC
To disable APC for a specific virtual host, add the following directive to the virtual host config or .htaccess:
php_flag apc.cache_by_default Off
Globally Disable APC
To disable APC globally, add the following directice to php.ini:
Then to enable APC on a per host basis, add the following directive to the virtual host config or .htaccess:
php_flag apc.cache_by_default On
This provides the granularity to disable/enable APC as needed in a virtual host environment.