Unable to remove limit on memory usage for PHP script.

Posted by Jess Telford on Server Fault See other posts from Server Fault or by Jess Telford
Published on 2011-06-16T03:04:27Z Indexed on 2011/06/22 8:24 UTC
Read the original article Hit count: 298

Filed under:
|
|

The Situation

I am having an issue with a PHP script getting the following error message:

Fatal error: Out of memory (allocated 359923712) (tried to allocate 72 bytes) in /path/to/piwik/core/DataTable.php on line 969

The script I'm running is: /path/to/piwik/misc/cron/archive.sh

I am assuming the numbers are Bytes, which means that total is approximately 360MB.

For all intents and purposes, I have increased the memory limits on the server well above 360MB, yet this is the number (give or take a byte) it consistently errors out at.

Please note: This question is not about fixing a memory leak in the script, nor about why the script itself is using so much memory. The script is part of the Piwik archiving process, so I cannot just fix any memory leaks, etc. For more info on this script and why I am increasing the memory limit, see "How to setup auto archiving"

The question

Given that the script is attempting to use over 360MB of memory, which I cannot change, why does it not seem possible for me to increase the amount of memory available to php on my server?


What I've tried

Increasing PHP's memory_limit

Given the php.ini file:

php -i | grep php.ini
Configuration File (php.ini) Path => /usr/local/lib
Loaded Configuration File => /usr/local/lib/php.ini

I have edited that file, so the memory_limit directive reads;

memory_limit = -1

Restart Apache, and check the new value has stuck;

$ php -i | grep memory_limit
memory_limit => -1 => -1

Run the script, and get the same error.

I've also tried 1G, 768M, etc, all to the same result (ie; no change).

Update 22nd June: Based on Vangel's help, I have attempted to set post_max_size to 20M in combination with setting memory_limit. Again, this has no effect.

Removing the memory limit on child processes of Apache

I have found and edited the httpd.conf file to make sure there is no RLimitMEM directive.

I then used WHM's Apache Configuration > Memory Usage Restrictions to generate a restriction, which it claimed was at 1000M (and confirmed by checking httpd.conf).

Both of these resulted in no change to the script erroring at 360MB.

Increasing the per process memory limits of Linux

The current limits set on the system:

$ ulimit -m
524288

$ ulimit -v
524288

I have attempted to set both of these to unlimited:

$ ulimit -m unlimited
$ ulimit -v unlimited

$ ulimit -m
unlimited

$ ulimit -v
unlimited

Once again, this has resulted in absolutely no improvement in my problem.


My setup

$ cat /etc/redhat-release
CentOS release 5.5 (Final)

$ uname -a
Linux example.com 2.6.18-164.15.1.el5 #1 SMP Wed Mar 17 11:30:06 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux

$ php -i | grep "PHP Version"
PHP Version => 5.2.9

$ httpd -V
Server version: Apache/2.0.63
Server built:   Feb  2 2011 01:25:12
Cpanel::Easy::Apache v3.2.0 rev5291
Server's Module Magic Number: 20020903:13
Server loaded:  APR 0.9.17, APR-UTIL 0.9.15
Compiled using: APR 0.9.17, APR-UTIL 0.9.15
Architecture:   64-bit
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/prefork"
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D HTTPD_ROOT="/usr/local/apache"
 -D SUEXEC_BIN="/usr/local/apache/bin/suexec"
 -D DEFAULT_PIDLOG="logs/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_LOCKFILE="logs/accept.lock"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"

Output of $ php -i: http://pastebin.com/EiRut6Nm

© Server Fault or respective owner

Related posts about linux

Related posts about php