Bug #65723 [Nab]: Memory limit of string
| From: | m dot banaszek at smartmedia dot com dot pl | Date: | Wed, 25 Sep 2013 08:03:21 +0000 |
| Subject: | Bug #65723 [Nab]: Memory limit of string | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-181768@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=65723&edit=1
ID: 65723
User updated by: m dot banaszek at smartmedia dot com dot pl
Reported by: m dot banaszek at smartmedia dot com dot pl
Summary: Memory limit of string
Status: Not a bug
Type: Bug
Package: Scripting Engine problem
Operating System: Windows 8
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Hello,
i'm very sorry there should be line : "$string .= $strb; ".
I tested your simplified code on my production machine. For 50 tests script fail
always on 480MB
I use windows serwer 2008 r2 x64, iis 7, php 5.4.14.
When use array for test memory usage grows up to 1,9GB as expected.
I found temporary solution "http://www.ntcore.com/4gb_patch.php".
after patch, string test use 1,5 GB memory and array over 3GB
Previous Comments:
------------------------------------------------------------------------
[2013-09-20 20:58:47] aharvey@php.net
There are some issues with your test: in its default "string" mode, memory usage
never actually increases. If I change it to "array" mode, it behaves how the
manual says it will â 81 iterations succeed ($strb is 10,000,000 bytes in size,
and the effective memory limit is 838,860,800 bytes), and then the script errors
out with an out of memory error (there are 810,000,000 bytes in the array, plus
overhead for the array itself, plus $strb, plus general overhead). Bear in mind
that the memory limit applies to the entire runtime, not individual variables.
A simpler, clearer test is this:
<?php
ini_set('memory_limit', '800M');
$buffer = '';
while (true) {
$buffer .= str_repeat(' ', 10000000);
printf("Length of buffer: %d\nMemory usage: %d\n", strlen($buffer),
memory_get_usage());
}
?>
In short, this behaves as expected and documented.
------------------------------------------------------------------------
[2013-09-20 11:24:10] m dot banaszek at smartmedia dot com dot pl
Description:
------------
The PHP manual now states, that strings are limited to 2GB. However in test
script, I specify a memory limit to 800MB. I wrote a PHP application where memory
usage is growing over time. Unfortunately the size of a single string variable
doesn't exceed memory limit of 300-400MB and my test stops. Testing my script on
5.4.17,18,19 and 5.3.10 of PHP versions, but any of this versions don't
supported my memory limit or 2GB memory.
Test script:
---------------
<?php
ini_set('memory_limit', '800M');
$string = '1234567890';
$strb = '';
for ($i = 0; $i < 1000000; $i++)
$strb .= $string;
$arr = array();
$i = 0;
$testType = 'string'; //'array'
while (1) {
$i++;
if ('string' == $testType) {
error_log((strlen($string) / 1000000) . ' - ' .
(memory_get_usage() / 1000000));
} else {
$arr[] = $strb . $i;
error_log((strlen($string) / 1000000) . ' - ' .
(memory_get_usage() / 1000000));
}
error_log((count($arr)) . ' - ' . (memory_get_usage() / 1000000)); }
Expected result:
----------------
Memory usage grow to about 800MB.
Actual result:
--------------
Memory error of 300-400MB. So the memory usage does not continually grow to 800MB.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65723&edit=1