Overview
APC (alternative php cache) is a module that provides opcode caching for PHP pages. It comes installed by default on our LAMP kicks and can be a major performance booster. However, this caching can sometimes interfere with applications or cause segmentation faults. Below are some tips on how to troubleshoot APC if you suspect it is an issue.
Troubleshooting APC
1. In /usr/share/doc/php53u-pecl-apc-(version number) on CentOS/RedHat, and /usr/share/doc/php-apc on Ubuntu, there is an apc.php file. If you copy that file to a web-accessible directory, it can give you many statistics about how APC is behaving, including hit rate, miss rate, connection rate, current usage, and fragmentation. Fragmentation and usage are particularly important for troubleshooting. If the system is fragmented, then items have been deleted. Items are not deleted by default unless the limit has been hit, so this is a good indication it has
been full recently. When the APC cache reaches maximum, most applications have no issue, but some can cause unexpected behavior, like segmentation faults. To test this theory, increase the apc.shm_size in the apc.ini (in /etc/php.d for RedHat/CentOS or /etc/php5/apache2
/conf.d for Ubuntu and restarting Apache.
a. You can also get the latest apc.php by: curl
https://raw2.github.com/php/pecl-caching-apc/master/apc.php > apc.php
2. Disable apc by setting enabled to 0 in the apc.ini. While this step can dramatically affect performance, it can very quickly determine if APC is indeed the issue, and without a deep-dive on the php code, this may be the only option left to you.
- If editing apc.shm_size on Ubuntu 10.04, do not include any units such as M, otherwise Apache will NOT start. For other versions of Linux, adding proper units is strongly recommended and in some versions, required.
Common Symptoms of APC shm_size Being Too Small:
1. Warning: include_once(): Unable to allocate memory for pool
2. Segmentation faults
3.Sluggish Apache performance
- In general large CMS – type applications like Drupal and WordPress benefit well from a shm_size of 128 MB 256 MB