php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52061 memory_limit above 2G
Submitted: 2010-06-12 02:56 UTC Modified: 2012-07-28 17:42 UTC
Votes:9
Avg. Score:4.2 ± 0.9
Reproduced:5 of 5 (100.0%)
Same Version:2 (40.0%)
Same OS:1 (20.0%)
From: mail-phpbugs at fushigi dot de Assigned: pajoye (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.2SVN-2010-06-12 (snap) OS: Linux/Centos-5
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mail-phpbugs at fushigi dot de
New email:
PHP Version: OS:

 

 [2010-06-12 02:56 UTC] mail-phpbugs at fushigi dot de
Description:
------------
PHP 5.2 doesn't coun't process memory_limit => 2048M in right way
in 32bit mode it works up to 4G, after that it would cause a fatal error, this seems ok, because of the memory limitations of 32bit :)
in 64bit its a REAL BUG, because after 2047M the memory limit DOESN'T MATCH, this means no memory limit is active !

as far as i have seen the memory limit for php51 isn't affectet this way because it walks in an error as of 2GB
and it seems in php53 the problem is fixed, here i tried to set limits up to 8GB and all worked fine.

The test script is from http://news.php.net/php.internals/48607 , but i think is shows the problem very well :)

is it possible to fix this, so it will behave as php-5.3 ?
or have the same matching as in 32bit version, so there is a limit if someone setting a too high value ?

i have found this problem as i wanted to get a customer from an old php-5.2.13 32bit machine on a newer php-5.2.13 64bit machine :(


32bit 5.2:
Running 400000 times with a 16383 bytes long string ('   ...')
>      0 -  0.000s:        0.1 /       0.2 MB
>  10000 -  1.294s:      166.7 /     177.5 MB
>  20000 -  2.453s:      333.2 /     355.1 MB
>  30000 -  3.988s:      499.7 /     532.4 MB
>  40000 -  5.700s:      666.3 /     709.5 MB
>  50000 -  7.614s:      832.8 /     886.9 MB
>  60000 -  9.838s:      999.3 /   1'064.0 MB
>  70000 - 11.592s:    1'165.9 /   1'241.3 MB
>  80000 - 12.943s:    1'332.4 /   1'418.6 MB
>  90000 - 19.795s:    1'498.9 /   1'595.7 MB
PHP Fatal error:  Allowed memory size of -2147483648 bytes exhausted (tried to allocate 40961 bytes) in /tmp/php-memtest.php on line 32

64bit 5.2:
Running 400000 times with a 16383 bytes long string ('   ...')
>      0 -  0.000s:        0.1 /       0.2 MB
>  10000 -  0.110s:      167.0 /     177.8 MB
>  20000 -  0.221s:      333.8 /     355.1 MB
>  30000 -  0.335s:      500.5 /     532.2 MB
>  40000 -  0.449s:      667.3 /     709.7 MB
>  50000 -  0.560s:      834.1 /     887.1 MB
>  60000 -  0.672s:    1'000.9 /   1'064.2 MB
>  70000 -  0.782s:    1'167.7 /   1'241.7 MB
>  80000 -  0.891s:    1'334.5 /   1'418.8 MB
>  90000 -  1.000s:    1'501.3 /   1'596.0 MB
> 100000 -  1.109s:    1'668.1 /   1'773.3 MB
> 110000 -  1.219s:    1'834.9 /   1'950.4 MB
> 120000 -  1.328s:    2'001.7 /   2'127.5 MB
> 130000 -  1.436s:    2'168.5 /   2'304.9 MB
> 140000 -  1.543s:    2'335.3 /   2'482.2 MB
> 150000 -  1.651s:    2'502.1 /   2'659.3 MB
> 160000 -  1.758s:    2'668.9 /   2'836.6 MB
> 170000 -  1.864s:    2'835.7 /   3'013.7 MB
> 180000 -  1.969s:    3'002.5 /   3'190.9 MB
> 190000 -  2.079s:    3'169.3 /   3'368.2 MB
> 200000 -  2.189s:    3'336.0 /   3'545.5 MB
> 210000 -  2.300s:    3'502.8 /   3'722.6 MB
> 220000 -  2.411s:    3'669.6 /   3'900.0 MB
> 230000 -  2.519s:    3'836.4 /   4'077.1 MB
> 240000 -  2.628s:    4'003.2 /   4'254.2 MB
> 250000 -  2.737s:    4'170.0 /   4'431.5 MB
> 260000 -  2.845s:    4'336.8 /   4'608.6 MB
> 270000 -  2.953s:    4'503.6 /   4'786.0 MB
> 280000 -  3.061s:    4'670.4 /   4'963.3 MB
> 290000 -  3.169s:    4'837.2 /   5'140.4 MB
> 300000 -  3.277s:    5'004.0 /   5'317.5 MB
> 310000 -  3.384s:    5'170.8 /   5'494.9 MB
> 320000 -  3.490s:    5'337.6 /   5'672.0 MB
> 330000 -  3.596s:    5'504.4 /   5'849.3 MB
> 340000 -  3.703s:    5'671.2 /   6'026.6 MB
> 350000 -  3.809s:    5'838.0 /   6'203.7 MB
> 360000 -  3.914s:    6'004.8 /   6'380.9 MB
> 370000 -  4.019s:    6'171.6 /   6'558.2 MB
> 380000 -  4.124s:    6'338.3 /   6'735.3 MB
> 390000 -  4.231s:    6'505.1 /   6'912.4 MB
> 400000 -  4.342s:    6'671.9 /   7'089.8 MB

Cleaning up 200001 output handlers
Done, total time:  4.638s, peak mem: 6'671.9 / 7'089.8 MB


########## Other Versions ######################
32bit 5.1:
Running 400000 times with a 16383 bytes long string ('   ...')
>      0 -  0.000s:        0.1 /       0.1 MB
>  10000 -  0.721s:      166.6 /     166.6 MB
>  20000 -  1.646s:      333.0 /     333.0 MB
>  30000 -  2.839s:      499.5 /     499.5 MB
>  40000 -  4.010s:      665.9 /     665.9 MB
>  50000 -  6.007s:      832.4 /     832.4 MB
>  60000 -  8.427s:      998.8 /     998.8 MB
>  70000 -  9.531s:    1'165.3 /   1'165.3 MB
>  80000 - 12.218s:    1'331.7 /   1'331.7 MB
>  90000 - 15.126s:    1'498.2 /   1'498.2 MB
> 100000 - 17.942s:    1'664.7 /   1'664.7 MB
Integer overflow in memory_limit check detected

64bit 5.1:
Running 400000 times with a 16383 bytes long string ('   ...')
>      0 -  0.000s:        0.1 /       0.1 MB
>  10000 -  0.116s:      166.7 /     166.7 MB
>  20000 -  0.235s:      333.3 /     333.3 MB
>  30000 -  0.356s:      499.9 /     499.9 MB
>  40000 -  0.473s:      666.5 /     666.5 MB
>  50000 -  0.586s:      833.1 /     833.1 MB
>  60000 -  0.698s:      999.7 /     999.7 MB
>  70000 -  0.807s:    1'166.3 /   1'166.3 MB
>  80000 -  0.916s:    1'332.9 /   1'332.9 MB
>  90000 -  1.024s:    1'499.5 /   1'499.5 MB
> 100000 -  1.133s:    1'666.1 /   1'666.1 MB
Integer overflow in memory_limit check detected


32bit 5.3:
Running 400000 times with a 16383 bytes long string ('   ...')
>      0 -  0.000s:        0.3 /       0.4 MB
>  10000 -  0.382s:      166.9 /     177.8 MB
>  20000 -  1.000s:      333.4 /     354.9 MB
>  30000 -  1.425s:      499.9 /     532.2 MB
>  40000 -  1.754s:      666.5 /     709.3 MB
>  50000 -  2.137s:      833.0 /     886.4 MB
>  60000 -  2.484s:      999.6 /   1'063.8 MB
>  70000 -  2.834s:    1'166.1 /   1'240.9 MB
>  80000 -  3.129s:    1'332.6 /   1'418.2 MB
>  90000 -  3.527s:    1'499.2 /   1'595.3 MB
PHP Fatal error:  Allowed memory size of -2147483648 bytes exhausted (tried to allocate 40961 bytes) in /tmp/php-memtest.php on line 32

64bit 5.3:
Running 400000 times with a 16383 bytes long string ('   ...')
>      0 -  0.000s:        0.6 /       0.6 MB
>  10000 -  0.112s:      167.4 /     178.2 MB
>  20000 -  0.226s:      334.2 /     355.5 MB
>  30000 -  0.340s:      501.0 /     532.8 MB
>  40000 -  0.453s:      667.8 /     710.2 MB
>  50000 -  0.568s:      834.6 /     887.5 MB
>  60000 -  0.681s:    1'001.4 /   1'064.6 MB
>  70000 -  0.792s:    1'168.2 /   1'242.2 MB
>  80000 -  0.903s:    1'335.0 /   1'419.3 MB
>  90000 -  1.014s:    1'501.8 /   1'596.4 MB
PHP Fatal error:  Allowed memory size of 2147483648 bytes exhausted (tried to allocate 40961 bytes) in /tmp/php-memtest.php on line 32



Test script:
---------------
<?php
ini_set("memory_limit", "2G");

function mib($b) {
     return $b ? number_format($b/1024/1204, 1, ".", "'") : "?";
}

function mgu($r, $p = false) {
     return mib($p ? memory_get_peak_usage($r) :  memory_get_usage($r));
}

function obs($i) {
     global $start;
     fprintf(STDERR, "> %6d - %6.3fs: %10s /%10s MB\n",
         $i,
         microtime(true)-$start,
         mgu(false), mgu(true)
     );
}

$loop = 400000;
$data = str_repeat(" ", 0x3fff);

fprintf(STDERR, "Running %d times with a %d bytes long string ('%s...')\n",
     $loop,
     strlen($data),
     substr($data, 0, 3)
);

$start = microtime(true);
for ($i = 0; $i < $loop; ++$i) {
     ob_start();
     echo $data;

     if (!($i % 10000)) {
         obs($i);
     }

     if ($i % 2) {
         ob_flush();
     } elseif ($i) {
         ob_end_clean();
     }
}
obs($i);

fprintf(STDERR, "\nCleaning up %d output handlers\n",
     ob_get_level()
);
while(ob_get_level())
     ob_end_clean();

fprintf(STDERR, "Done, total time: %6.3fs, peak mem: %s / %s MB\n",
     microtime(true)-$start,
     mgu(false, true), mgu(true, true)
);
?>

Expected result:
----------------
Running 400000 times with a 16383 bytes long string ('   ...')
>      0 -  0.000s:        0.1 /       0.2 MB
>  10000 -  0.110s:      167.0 /     177.8 MB
>  20000 -  0.221s:      333.8 /     355.1 MB
>  30000 -  0.335s:      500.5 /     532.2 MB
>  40000 -  0.449s:      667.3 /     709.7 MB
>  50000 -  0.560s:      834.1 /     887.1 MB
>  60000 -  0.672s:    1'000.9 /   1'064.2 MB
>  70000 -  0.782s:    1'167.7 /   1'241.7 MB
>  80000 -  0.891s:    1'334.5 /   1'418.8 MB
>  90000 -  1.000s:    1'501.3 /   1'596.0 MB
PHP Fatal error:  Allowed memory size of 2147483648 bytes exhausted (tried to allocate 40961 bytes) in /tmp/php-memtest.php on line 32

Actual result:
--------------
Running 400000 times with a 16383 bytes long string ('   ...')
>      0 -  0.000s:        0.1 /       0.2 MB
>  10000 -  0.110s:      167.0 /     177.8 MB
>  20000 -  0.221s:      333.8 /     355.1 MB
>  30000 -  0.335s:      500.5 /     532.2 MB
>  40000 -  0.449s:      667.3 /     709.7 MB
>  50000 -  0.560s:      834.1 /     887.1 MB
>  60000 -  0.672s:    1'000.9 /   1'064.2 MB
>  70000 -  0.782s:    1'167.7 /   1'241.7 MB
>  80000 -  0.891s:    1'334.5 /   1'418.8 MB
>  90000 -  1.000s:    1'501.3 /   1'596.0 MB
> 100000 -  1.109s:    1'668.1 /   1'773.3 MB
> 110000 -  1.219s:    1'834.9 /   1'950.4 MB
> 120000 -  1.328s:    2'001.7 /   2'127.5 MB
> 130000 -  1.436s:    2'168.5 /   2'304.9 MB
> 140000 -  1.543s:    2'335.3 /   2'482.2 MB
> 150000 -  1.651s:    2'502.1 /   2'659.3 MB
> 160000 -  1.758s:    2'668.9 /   2'836.6 MB
> 170000 -  1.864s:    2'835.7 /   3'013.7 MB
> 180000 -  1.969s:    3'002.5 /   3'190.9 MB
> 190000 -  2.079s:    3'169.3 /   3'368.2 MB
> 200000 -  2.189s:    3'336.0 /   3'545.5 MB
> 210000 -  2.300s:    3'502.8 /   3'722.6 MB
> 220000 -  2.411s:    3'669.6 /   3'900.0 MB
> 230000 -  2.519s:    3'836.4 /   4'077.1 MB
> 240000 -  2.628s:    4'003.2 /   4'254.2 MB
> 250000 -  2.737s:    4'170.0 /   4'431.5 MB
> 260000 -  2.845s:    4'336.8 /   4'608.6 MB
> 270000 -  2.953s:    4'503.6 /   4'786.0 MB
> 280000 -  3.061s:    4'670.4 /   4'963.3 MB
> 290000 -  3.169s:    4'837.2 /   5'140.4 MB
> 300000 -  3.277s:    5'004.0 /   5'317.5 MB
> 310000 -  3.384s:    5'170.8 /   5'494.9 MB
> 320000 -  3.490s:    5'337.6 /   5'672.0 MB
> 330000 -  3.596s:    5'504.4 /   5'849.3 MB
> 340000 -  3.703s:    5'671.2 /   6'026.6 MB
> 350000 -  3.809s:    5'838.0 /   6'203.7 MB
> 360000 -  3.914s:    6'004.8 /   6'380.9 MB
> 370000 -  4.019s:    6'171.6 /   6'558.2 MB
> 380000 -  4.124s:    6'338.3 /   6'735.3 MB
> 390000 -  4.231s:    6'505.1 /   6'912.4 MB
> 400000 -  4.342s:    6'671.9 /   7'089.8 MB

Cleaning up 200001 output handlers
Done, total time:  4.638s, peak mem: 6'671.9 / 7'089.8 MB

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-19 22:47 UTC] felipe@php.net
Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=300606
Log: - Fixed bug #52061 (memory_limit above 2G)
# MFH: zend_atol()
 [2010-06-19 22:48 UTC] felipe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: felipe
 [2010-06-19 22:48 UTC] felipe@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2010-06-20 00:32 UTC] felipe@php.net
-Status: Closed +Status: Assigned -Assigned To: felipe +Assigned To: pajoye
 [2010-06-20 12:58 UTC] mail-phpbugs at fushigi dot de
i have testet it on my test machines and the memory limit is working fine :)

thx for the quick fix :)
 [2011-05-23 16:58 UTC] jsweeny at gmail dot com
I am having this same problem; but I'm running php version 5.1.6.  I have 12 GB of memory and am running 64-bit Linux.  Why did you say that version 5.1 was okay?  Something about "walking in an error"?

If a fix was created for version 5.2, can one also be created for version 5.1?

thanks!
 [2012-07-28 17:42 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 [2012-07-28 17:42 UTC] nikic@php.net
Closing as this was already fixed and 5.1 is not relevant anymore.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 13:01:29 2024 UTC