PHP: Require_once(): Unable To Allocate Memory For Pool Error and Solution


How do I fix these php warnings?

This error is usually related to Alternative PHP Cache (APC). APC is a free and open opcode cache for PHP. Its goal is to provide a free, open, and robust framework for caching and optimizing PHP intermediate code.

Solution

Edit the file /etc/php.d/apc.ini (Debian and/or Ubuntu Linux user edit the/etc/php5/conf.d/apc.ini), enter:
# vi /etc/php.d/apc.ini
Make sure the mktemp-style file_mask to pass to the mmap module is correct and valid one:

 
apc.mmap_file_mask=/tmp/apc.XXXXXX

Next make sure the size of each shared memory segment, with M/G suffix is set correct as per your requirements. In my case it was set to 8M:

 
; increased to 96M
apc.shm_size=96M

You need to adjust the number of seconds a cache entry is allowed to idle in a slot in case this cache entry slot is needed by another entry:

 
apc.ttl=3600

The number of seconds a user cache entry is allowed to idle in a slot in case this cache entry slot is needed by another entry:

 
apc.user_ttl=3600

The number of seconds that a cache entry may remain on the garbage-collection list.

 
apc.gc_ttl=3600

Save and close the file. Make sure you adjust the values as per your web-app requirements.Restart the Apache 2 web server:
# service httpd restart
If you are using the Lighttpd instead of Apache2 web-server, restart the Lighttpd web server:
# service lighttpd restart
If you are using Nginx instead of Apache2 or Lighttpd, restart the Nginx web server:
# service nginx restart
OR
# /usr/local/nginx/sbin/nginx -s reload

Tip: Find out your APC memory usage and hit ratio

You need to find out exact memory usage and hit ratio so that you can set apc.ttl and apc.shm_size as per your work load. Copy /usr/share/php-pecl-apc/apc.php to your /var/www/html directory i.e. Apache DocumentRoot:
# cp /usr/share/php-pecl-apc/apc.php /var/www/html
Edit /var/www/html/apc.php and set the admin password :

 
defaults('ADMIN_PASSWORD','YOUR-NEW-PASSWORD-HERE');

Save and close the file. Fire a web-browser and type the url:
http://server-ip-here/apc.php
OR
http://server1.cyberciti.biz/apc.php
Sample outputs:

Apc Memory Status and Hit Ratio

Fig.01: Apc Memory Status and Hit Ratio

From the above graph I’m getting 100.0% hit ratio and I’ve used almost all memory. I need to increase memory and reduce ttl value so that I will not get memory allocation error.

References:
  1. PHP APC documentation.

 

Next example help too:

apc.enabled = 1
apc.enable_cli = 1
apc.max_file_size = 2M
apc.shm_size = 256M
apc.ttl = 120
apc.user_ttl = 120
;stat should normally be placed at 1 for production / live environment
apc.stat = 0
apc.slam_defense = 0
apc.mmap_file_mask = «/tmp/apc.XXXXXX»