PHP cannot use 300 MB of RAM

I am trying to increase the allowed memory for a specific PHP script. No matter what I do, for example:

ini_set('memory_limit', '512M');

... the script always ends with a memory of about 300 MB:

Fatal error: Out of memory (allocated 25165824) (tried to allocate 343810589 bytes) in \\Foo\phpQuery\phpQuery.php on line 255

I checked in several ways what memory_limitreally changed. The problem is that PHP cannot physically allocate a total of 300 MB of memory (25165824 bytes + 343810589 bytes = 352 MB).

I tried PHP / 5.3.0 and PHP / 5.3.9 on two different Windows computers with the following specifications:

  • Windows XP / Windows Server 2003 (both computers are 32-bit blocks with 1 GB or RAM)
  • Official 32-bit VC9 binaries for PHP
  • Works as an Apache 2.2 module (third-party 32-bit VC9 binaries)

I understand that using half of the physical memory will force me to exchange and slow down, but I just need to make sure that the script is working, so it can be deployed to a live server. I also tried larger values ​​(which missed the same error) and smaller values ​​(by using my script to reach the limit or Apache crashing).

What could be the source of this clearly tough memory limitation?

# 1: Windows Server 2003 ( VMWare). "" 2 GB , 1152 . , 886 1,5 . , .

# 2: , memory_limit . ini_get(), phpinfo(). , , ; my PHP. , :

Out of memory (allocated 25165824) (tried to allocate 343810589 bytes)
Allowed memory size of 25165824 bytes exhausted (tried to allocate 343810589 bytes)

script .

+6
3

OOM .

, PHP , .

, / .

+4

max_input_time, , PHP memory_limit, max_input_time (-1 ).

0

, 250 . apache, ThreadsPerChild ( /conf/extra/httpd-mpm.conf), ThreadsPerChild 150 50 , ... :

echo "Memory limit: ".ini_get("memory_limit")."<br><br>";
$a=array();
if (ob_get_level() == 0) ob_start();
for($i=0;$i<200;$i++)
{
    $a[]=str_pad('',1024*1024*32);
    echo "Pass ".$i.", memory used: ".number_format((memory_get_usage())/(1024*1024),0)." MB<br>";
    ob_flush();
    flush();
}
0

All Articles