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=51523&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=51523&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=51523&r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=51523&r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=51523&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=51523&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=51523&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=51523&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=51523&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=51523&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=51523&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=51523&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=51523&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=51523&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=51523&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51523&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=51523&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=51523&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=51523&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=51523&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=51523&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=51523&r=mysqlcfg