PHP script is using more memory than memory_limit

Zagorax

Verified User
Joined
Jan 11, 2011
Messages
67
Hi all,

I have a CentOS machine running DirectAdmin with the following relevant options.conf directives:

Code:
webserver=nginx_apache
php1_release=5.5
php1_mode=suphp

The ini filre is in /usr/local/php55/lib/php.ini and memory_limit is set to 128M. The line is correctly uncommented and parsed, with phpinfo() I can see that the configuration files is read correctly and the limit set.

On the same machine, I have csf running. Which is instructed to send an email everytime a process uses more than 200M of memory. I keep receiving emails like the following;

Code:
Time:         Tue Jun  7 01:48:18 2016 +0200
Account:      ***
Resource:     Virtual Memory Size
Exceeded:     257 > 200 (MB)
Executable:   /usr/local/php55/bin/php-cgi55
Command Line: /usr/local/php55/bin/php-cgi55 /home/****/domains/***/public_html/corsobase/index.php
PID:          15752 (Parent PID:11972)
Killed:       No

Is this normal? If so, why is this happening? Is csf failing while reading the memory used by the process? Is php ignoring the memory_limit?

Let me know if you need additional info to debug it. Thanks!
 
Hello,

It is "Virtual Memory Size", check this: http://serverfault.com/questions/138427/top-what-does-virtual-memory-size-mean-linux-ubuntu

test it with the script, create /root/func.php with the following content:

PHP:
#!/usr/local/php -n
<?php
function someBigValue($m) {
    return str_repeat('SOME BIG STRING', 1024*$m*300);
}

echo "String memory usage test.\n\n";
$m=1;
while (true)
{
    $a = someBigValue($m);
    echo "[".$m."] Used memory ". memory_get_usage()." (";
    echo exec("ps axo vsz,rss,cmd | grep -v grep | grep func.php | awk '{print \"VSZ=\"$1\" KiB, RSS=\"$2\" KiB\"}'") .")\n";
    unset($a);
    sleep (1);
    $m++;
}
you will see something similar to:

Code:
[26] Used memory 120029608 (VSZ=490436 KiB, RSS=139844 KiB)
[27] Used memory 124637608 (VSZ=494788 KiB, RSS=144344 KiB)
[28] Used memory 129245608 (VSZ=499396 KiB, RSS=148844 KiB)
[29] Used memory 133853608 (VSZ=503748 KiB, RSS=153344 KiB)
PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 138240001 bytes) in /root/func.php on line 4

at 29 iteration the script used 503Mb of virtual memory, and only 133Mb for data.
 
Back
Top