From: devis at lucato dot it Operating system: Linux PHP version: 5.2.4 PHP Bug Type: Performance problem Bug description: Excessive memory allocation
Description: ------------ I'm having memory usage problems as in Bug #41053 (http://bugs.php.net/bug.php?id=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: --------------- <?php function getMemoryUsage() { return round(memory_get_usage() / (1024*1024), 1)." MB"; } function printMemoryUsage() { print("Memory = ".getMemoryUsage()." <br>\n"); } printMemoryUsage(); $end = 1000000; $array = array(); printMemoryUsage(); for($i = 0; $i < $end; $i++) { $array[$i] = 0; } printMemoryUsage(); ?> Expected result: ---------------- Well, I expect a better memory usage. Actual result: -------------- Running matthieu script (see below) on different systems I get this results: 32 BIT SERVER ------------- PHP 5.2.4 result is 68.9 MB PHP 4.4.4 result is 57.5 MB 64 BIT SERVER ------------- PHP 5.2.4 result is 130.2 MB PHP 4.4.4 result is 99.6 MB -- Edit bug report at http://bugs.php.net/?id=42565&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=42565&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=42565&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=42565&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=42565&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=42565&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=42565&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=42565&r=needscript Try newer version: http://bugs.php.net/fix.php?id=42565&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=42565&r=support Expected behavior: http://bugs.php.net/fix.php?id=42565&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=42565&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=42565&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=42565&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=42565&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=42565&r=dst IIS Stability: http://bugs.php.net/fix.php?id=42565&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=42565&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=42565&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=42565&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=42565&r=mysqlcfg