Pages

Friday, April 12, 2013

Error PHP Fatal error: Out of memory (allocated 24641536) (tried to allocate 24381441 bytes) on cPanel server with php scripts

Today came across with the memory exhausted error and while investigation note that after increasing the memory in server php.ini file even though increased php memory limit for the particular user as server is suphp enabled, but did not help…
 
While browsing the site I find the error as below under error logs :

==========================================
[root@server/home/username/public_html]# tail -f error_log
[01-May-2012 20:45:55] PHP Fatal error:  Out of memory (allocated 24641536) (tried to allocate 24381441 bytes) in /home/username/public_html/filename.php on line 117

==========================================

Soution 1 :


1. If server is suphp enabled then do as below ::
>> create Or copy server php.ini under public_html as below :
#cp /usr/local/lib/php.ini /home/username/public_html
Then open the php.ini file
# vi  /home/username/public_html/php.ini
Find for the memory_limit parameter and change the value as below :
memory_limit = 32 MB
To
memory_limit = 64 MB
Save the file.
>> Now open the .htaccess file under your public_html
#vi /home/username/public_html/.htaccess
and enter the code below :
suPHP_ConfigPath /home/username/public_html
Save the file.
2. Now try to access your page again and check if that help to resolve the issue.

In my case solution 1 did not help and then I checked the issue further and came to know that the issue was with the apache memory limit. I did check as below :

Solutions 2::
1. Checked the parameter RLimitMEM  under apache configuration file.
# vi /etc/httpd/conf/httpd.conf
Find for RLimitMEM
you will see something like below :
RLimitMEM 154857600 154857600
RLimitCPU 150 200
RLimitNPROC 25 30
Just increase the value of RLimitMEM , In my case I did as below ::
RLimitMEM 184857600 184857600
NOTE :: if you don’t find the value in httpd.conf, please do check in the file /etc/httpd/conf/includes/pre_main_global.conf
and then restart apache on the server.
# service httpd restart

and now try to access your site. your site will work like a charm without any error.

No comments:

Post a Comment