|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42565 Excessive memory allocation
Submitted: 2007-09-05 13:59 UTC Modified: 2007-09-06 11:08 UTC
From: devis at lucato dot it Assigned:
Status: Not a bug Package: Performance problem
PHP Version: 5.2.4 OS: Linux
Private report: No CVE-ID: None
 [2007-09-05 13:59 UTC] devis at lucato dot it
I'm having memory usage problems as in Bug #41053 (

PHP allocates much more memory on 64 bit systems, probably using 64 bit variables to describe the array structure.

The following script uses 130Mb for 2Mb of data but in production systems the situation gets worse, working with big arrays and concurrent connections the wasted memory is much more... 

Is there any suggestion/trick/setting useful (apart code optimizaztion, rolling back to 32 bit hardware or doubling available ram) ? 
Any news in PHP development about memory optimization ? Perhaps some settings to disable or reduce the internal arrays structure ?

Reproduce code:
function getMemoryUsage()
	return round(memory_get_usage() / (1024*1024), 1)." MB";
function printMemoryUsage()
	print("Memory = ".getMemoryUsage()." <br>\n");

$end = 1000000;
$array = array();
for($i = 0; $i < $end; $i++)
	$array[$i] = 0;

Expected result:
Well, I expect a better memory usage.

Actual result:
Running matthieu script (see below) on different systems I get this results:

PHP 5.2.4 result is 68.9 MB
PHP 4.4.4 result is 57.5 MB

PHP 5.2.4 result is 130.2 MB
PHP 4.4.4 result is 99.6 MB


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-09-06 11:08 UTC]
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Aug 13 09:01:24 2020 UTC