From: tdondich at groundworkopensource dot com Operating system: Ubuntu Edgy PHP version: 5.2.0 PHP Bug Type: Apache2 related Bug description: Apache2 with simple PHP Script consumes all available memory
Description: ------------ Using: - Apache 2.2.4 - PHP 5.2.0 w/ sessions Description: When running this simple script, Apache2 will consume all available memory and the script will not complete (with no memory limit and high time limit) until all memory is taken by Apache 2 process and system starts to fail (swap extensively until nothing is responsive). Reproduce code: --------------- <?php session_start(); $myarray = array(); $numOfIterations = 100000; // Set to 10000 to see the script succeed for($counter = 0; $counter < $numOfIterations; $counter++) { $myarray[$counter] = 'jkdfjklsdfjklfsdhjklsdfhildfnifsdnsdfnlfsdnklfsdnkglgfnkl;nmklsdf'; } // copy the array, just for kicks $_SESSION['test'] = $myarray; sleep(5); // See the memory usage in top for awhile print("Completed."); ?> Expected result: ---------------- Apache2 process (pre-fork) will consume all available memory and continue to climb until system swaps excessively and then becomes unresponsive. Changing the $numOfIterations to 10000 causes it to succeed. By my account, the memory needed approx for each array is: 100000 X 66 = 6600000bytes 6600000 / 1048576 = 6 megabytes Even when copying it to $_SESSION, it should only take 12 megs, plus maybe a little more for overhead (array constructs, program execution). We're seeing consumption of over a gigabyte and growing with one script execution. Actual result: -------------- TAKEN FROM TOP: Mem: 1035632k total, 1021568k used, 14064k free, 1208k buffers Swap: 3028212k total, 432996k used, 2595216k free, 40336k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 16094 tdondich 16 0 344m 86m 5172 S 1 8.6 15:16.51 java 4205 root 15 0 197m 19m 3960 S 1 1.9 31:37.61 Xorg 28209 daemon 18 0 779m 704m 2148 D 1 69.7 0:04.34 httpd No other pages being served on this box. The script was continuing to execute at this time. -- Edit bug report at http://bugs.php.net/?id=40222&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=40222&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=40222&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=40222&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=40222&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=40222&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=40222&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=40222&r=needscript Try newer version: http://bugs.php.net/fix.php?id=40222&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=40222&r=support Expected behavior: http://bugs.php.net/fix.php?id=40222&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=40222&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=40222&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=40222&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=40222&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=40222&r=dst IIS Stability: http://bugs.php.net/fix.php?id=40222&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=40222&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=40222&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=40222&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=40222&r=mysqlcfg