Bug #51523 [Opn]: Memory leak on fread()
Edit report at http://bugs.php.net/bug.php?id=51523edit=1 ID: 51523 User updated by: evilzluk at gmail dot com Reported by: evilzluk at gmail dot com Summary: Memory leak on fread() Status: Open Type: Bug Package: Performance problem Operating System: Linux PHP Version: Irrelevant New Comment: Description: The problem is the fread() uses a normal amount of a memory. But there are too many unallocated anonymous memory pages. So if the file size 2G the script may cause eating up to 2G of RAM. But the script's runtime memory is 5M. The problem is occured even if: $fp = fopen($file, rb); while(!feof($fp)) fread($fp, 1024); fclose($fp); After that the memory isn't released so we have a garbadge in the memory. Test script: --- ?php $file = A.very.big.file.avi; ob_start(); $fp = fopen($file, rb); if ($fp) { while(!feof($fp)) { echo(fread($fp, 1024)); if (ob_get_length()) { ob_flush(); flush(); ob_end_flush(); } } fclose($fp); } @ob_flush(); @flush(); @ob_end_flush(); @ob_end_clean(); ? Expected result: The total amount of a memory usage should be at least php script runtime memory usage + 1024 (+ some buffer (up to 8192)). But not almost all the physical memory (0...unlimited) Previous Comments: [2010-04-10 01:06:50] evilzluk at gmail dot com Description: The problem is the fread() uses a normal amount of a memory. But there are too many unallocated anonymous memory pages. So if the file size 2G the script may cause eating up to 2G of RAM. But the script's runtime memory is 5M. The problem is occured even if: $fp = fopen($file, rb); while(!feof($fp)) fread($fp, 1024); fclose($fp); After that the memory isn't released so we have a garbadge in the memory. Test script: --- ?php $file = A.very.big.file.avi; ob_start(); $fp = fopen($file, wb); if ($fp) { while(!feof($fp)) { echo(fread($fp, 1024)); if (ob_get_length()) { ob_flush(); flush(); ob_end_flush(); } } fclose($fp); @ob_flush(); @flush(); @ob_end_flush(); @ob_end_clean(); } ? Expected result: The total amount of a memory usage should be at least php script runtime memory usage + 1024 (+ some buffer (up to 8192)). But not almost all the physical memory (0...unlimited) -- Edit this bug report at http://bugs.php.net/bug.php?id=51523edit=1
Bug #51523 [Opn-Csd]: Memory leak on fread()
Edit report at http://bugs.php.net/bug.php?id=51523edit=1 ID: 51523 User updated by: evilzluk at gmail dot com Reported by: evilzluk at gmail dot com Summary: Memory leak on fread() -Status: Open +Status: Closed Type: Bug Package: Performance problem Operating System: Linux PHP Version: Irrelevant New Comment: resolved adding to cronjob: sync echo 1 /proc/sys/vm/drop_caches echo 2 /proc/sys/vm/drop_caches echo 3 /proc/sys/vm/drop_caches sync Previous Comments: [2010-04-10 17:05:17] evilzluk at gmail dot com Description: The problem is the fread() uses a normal amount of a memory. But there are too many unallocated anonymous memory pages. So if the file size 2G the script may cause eating up to 2G of RAM. But the script's runtime memory is 5M. The problem is occured even if: $fp = fopen($file, rb); while(!feof($fp)) fread($fp, 1024); fclose($fp); After that the memory isn't released so we have a garbadge in the memory. Test script: --- ?php $file = A.very.big.file.avi; ob_start(); $fp = fopen($file, rb); if ($fp) { while(!feof($fp)) { echo(fread($fp, 1024)); if (ob_get_length()) { ob_flush(); flush(); ob_end_flush(); } } fclose($fp); } @ob_flush(); @flush(); @ob_end_flush(); @ob_end_clean(); ? Expected result: The total amount of a memory usage should be at least php script runtime memory usage + 1024 (+ some buffer (up to 8192)). But not almost all the physical memory (0...unlimited) [2010-04-10 01:06:50] evilzluk at gmail dot com Description: The problem is the fread() uses a normal amount of a memory. But there are too many unallocated anonymous memory pages. So if the file size 2G the script may cause eating up to 2G of RAM. But the script's runtime memory is 5M. The problem is occured even if: $fp = fopen($file, rb); while(!feof($fp)) fread($fp, 1024); fclose($fp); After that the memory isn't released so we have a garbadge in the memory. Test script: --- ?php $file = A.very.big.file.avi; ob_start(); $fp = fopen($file, wb); if ($fp) { while(!feof($fp)) { echo(fread($fp, 1024)); if (ob_get_length()) { ob_flush(); flush(); ob_end_flush(); } } fclose($fp); @ob_flush(); @flush(); @ob_end_flush(); @ob_end_clean(); } ? Expected result: The total amount of a memory usage should be at least php script runtime memory usage + 1024 (+ some buffer (up to 8192)). But not almost all the physical memory (0...unlimited) -- Edit this bug report at http://bugs.php.net/bug.php?id=51523edit=1
[PHP-BUG] Bug #51523 [NEW]: Memory leak on fread()
From: Operating system: Linux PHP version: Irrelevant Package: Performance problem Bug Type: Bug Bug description:Memory leak on fread() Description: The problem is the fread() uses a normal amount of a memory. But there are too many unallocated anonymous memory pages. So if the file size 2G the script may cause eating up to 2G of RAM. But the script's runtime memory is 5M. The problem is occured even if: $fp = fopen($file, rb); while(!feof($fp)) fread($fp, 1024); fclose($fp); After that the memory isn't released so we have a garbadge in the memory. Test script: --- ?php $file = A.very.big.file.avi; ob_start(); $fp = fopen($file, wb); if ($fp) { while(!feof($fp)) { echo(fread($fp, 1024)); if (ob_get_length()) { ob_flush(); flush(); ob_end_flush(); } } fclose($fp); @ob_flush(); @flush(); @ob_end_flush(); @ob_end_clean(); } ? Expected result: The total amount of a memory usage should be at least php script runtime memory usage + 1024 (+ some buffer (up to 8192)). But not almost all the physical memory (0...unlimited) -- Edit bug report at http://bugs.php.net/bug.php?id=51523edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=51523r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=51523r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=51523r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=51523r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=51523r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=51523r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=51523r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=51523r=needscript Try newer version: http://bugs.php.net/fix.php?id=51523r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=51523r=support Expected behavior: http://bugs.php.net/fix.php?id=51523r=notwrong Not enough info: http://bugs.php.net/fix.php?id=51523r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=51523r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=51523r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51523r=php4 Daylight Savings:http://bugs.php.net/fix.php?id=51523r=dst IIS Stability: http://bugs.php.net/fix.php?id=51523r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=51523r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=51523r=float No Zend Extensions: http://bugs.php.net/fix.php?id=51523r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=51523r=mysqlcfg