From:             frode dot guldberg at exense dot com
Operating system: Windows XP
PHP version:      5.2.5
PHP Bug Type:     Performance problem
Bug description:  Huge memory usage

Description:
------------
In a for-loop I concatenate two strings. If I at the same time fill a
relatively small array, I get a huge memory consumption. This only happens
if I concatenate the two strings using '.'. If I use '.=' the memory usage
is as expected.

Reproduce code:
---------------
<?php

$string = str_repeat('This is a teststring.', 50);

echo 'Length: '.strlen($string).'<br>';
echo 'Memory Before:'.memory_get_usage(true).'<br>';

for($i = 1; $i <= 2000; $i++)
{
//      $newstring .= $string; //This uses an expected amount of mem.
        $newstring = $newstring . $string; //This uses very much mem.

        for($j = 1; $j <= 10; $j++)
        {
                $array[] = 'test';
        }
}
echo 'Memory After:'.memory_get_usage(true).'<br>';
echo 'Total Length of String: '.strlen($newstring).'<br>';

?>

Expected result:
----------------
Length: 1050
Before:262144
After:4456448
Length: 2100000


Actual result:
--------------
Length: 1050
Before:262144
After:161742848
Length: 2100000

-- 
Edit bug report at http://bugs.php.net/?id=44069&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=44069&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=44069&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=44069&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=44069&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=44069&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=44069&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=44069&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=44069&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=44069&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=44069&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=44069&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=44069&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=44069&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=44069&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=44069&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=44069&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=44069&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=44069&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=44069&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=44069&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=44069&r=mysqlcfg

Reply via email to