|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44069 Huge memory usage with concatenation using . instead of .=
Submitted: 2008-02-07 13:39 UTC Modified: 2008-02-14 15:20 UTC
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:3 (100.0%)
From: frode dot guldberg at exense dot com Assigned: dmitry (profile)
Status: Closed Package: Performance problem
PHP Version: 5.2.5 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
29 + 11 = ?
Subscribe to this entry?

 [2008-02-07 13:39 UTC] frode dot guldberg at exense dot com
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:

$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
Length: 2100000

Actual result:
Length: 1050
Length: 2100000


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-02-13 18:25 UTC]
Dmitry, can you check this out please? The example script kills my machine totally if I don't use the .= :)
 [2008-02-14 14:49 UTC]
This bug has been fixed in CVS.

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

PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri May 14 14:01:23 2021 UTC