I am too frustrated with PHP APC caching system and I wanted to remove/disable it completely from my server. I am using PHP with Nginx installed on Debian Squeeze, is there any way of doing it ?
-
3Why are you frustrated by it? – Tom O'Connor Nov 23 '11 at 12:05
-
Now and then I am getting **Unable to allocate memory for pool error**. I have tried many fixes given here but none of them worked for me. – Vineet Sharma Nov 23 '11 at 12:18
-
1Not an answer to your question (since the answers have been given below), but your error is pretty common. I just answered a question here which contains a fix for it: http://serverfault.com/questions/333996/unable-to-allocate-memory-for-pool-how-to-fix-it/334821#334821 – Till Nov 25 '11 at 16:19
4 Answers
Instead of removing APC, which will cause a massive performance hit, and effectively shoot yourself in the foot..
Try this: in /etc/php5/conf.d/apc.ini:
extension=apc.so
apc.shm_size=128M
apc.shm_segments=1
apc.max_file_size=5M
apc.num_files_hint=10000
apc.slam_defense = 0
apc.write_lock=1
You can increase apc.shm_size
to a value bigger than 128, say 512 if you had sufficient free RAM.
I did this on a server I run, and never ever see Unable to allocate memory for pool errors.

- 27,480
- 10
- 73
- 148
Either remove /opt/php5/etc/conf.d/apc.ini
or comment all lines in it with a ;
. Don't forget to restart your webserver afterwards.
Also check '/etc//php5/apache2/php.ini' for 'extension=apc.so' to outcomment.
If you still have the sources around, you could try to do a make uninstall
afterwards. I don't know if the makefile contains this target.
If you didn't install something beside what Squeeze offers, a simple apt-get remove php-apc
should do the trick.

- 98,649
- 14
- 180
- 226
-
I compiled it from the source by followin the tutorial given here http://vladgh.com/blog/install-nginx-and-php-php-fpm-mysql-and-apc – Vineet Sharma Nov 23 '11 at 11:50
-
It clearly states in that tutorial where you enabled APC. Hint: "You will have to add the extension in php.ini" – pauska Nov 23 '11 at 12:14
The solution is to increase memory allocated to APC.
Using a TTL of 0 means that APC will flush all the cache when it runs out of memory. The error don't appear anymore but it makes APC far less efficient. It's a no risk, no trouble, "I don't want to do my job" decision. APC is not meant to be used that way. You should choose a TTL high enough so the most accessed pages won't expire. The best is to give enough memory so APC don't need to flush cache.
Just read the manual to understand how ttl is used : http://www.php.net/manual/en/apc.configuration.php#ini.apc.ttl
You can increase memory allocated by increasing apc.shm_size.
If APC is compiled to use Shared Segment Memory you will be limited by your operating system. Type this command to see your system limit for each segment :
sysctl -a | grep -E "shmall|shmmax"
To alocate more memory you'll have to increase the number of segments with the parameter apc.shm_segments.
If APC is using mmap memory then you have no limit. The amount of memory is still defined by the same option apc.shm_size.
If there's not enough memory on the server, then use filters option to prevent less frequently accessed php files to be cached.
But never use a TTL of 0.
Use apc.php to check your config. You'll see what is really allocated and how it is used. The graphs must remain stable after hours, if they are completly changing at each refresh, then it means that your setup is wrong (APC is flushing everything). Allocate 20% than what APC really use as a security margin, and check it on a regular basis.
The default of allowing only 32MB is ridiculously low. PHP was designed when a servers were 64MB and most script were using one php file per page. Nowadays solutions like Magento require more than 10k files (~60Mb in APC). You should allow enough memory so most of php files are always cached. It's not a waste, it's more efficient to keep opcode in ram rather than having the corresponding raw php in file cache. Nowadays we can find dedicated servers with 24Gb of memory for as low as $150, so don't hesitate to allow several GB to APC. I put 2GB out of 24GB on a server hosting 5Magento stores and ~40 wordpress website, APC uses 1.2GB. Count 64MB for Magento installation, 20MB for a Wordpress with some plugins.

- 224
- 3
- 13