Bug #75511 [NEW]: fread not free unused buffer.
| From: | mix5003 at gmail dot com | Date: | Fri, 10 Nov 2017 08:53:53 +0000 |
| Subject: | Bug #75511 [NEW]: fread not free unused buffer. | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-212536@lists.php.net to get a copy of this message | ||
From: mix5003 at gmail dot com
Operating system: *
PHP version: Irrelevant
Package: Performance problem
Bug Type: Bug
Bug description:fread not free unused buffer.
Description:
------------
When use fread to read multiple small files with large buffer.
it may make a memory limit error.
i think it becuase php alloc memory equals length that i send to fread
and it not trim to actual size of string. so many small string can reach
a memory limit.
or is it normal behavior?
Test script:
---------------
<?php
ini_set('memory_limit', '256M');
// create file
@mkdir('tmp_file');
for($i=0;$i<300;$i++){
file_put_contents("tmp_file/{$i}.txt", $i);
}
// read file
$data = [];
for($i=0;$i<300;$i++){
$fp = fopen("tmp_file/{$i}.txt", "r");
$data[$i] = fread($fp, 1024 * 1024);
fclose($fp);
echo strlen($data[$i])." ".memory_get_usage()."\n";
}
Expected result:
----------------
it can run normally. no memory allocate error.
Actual result:
--------------
Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to
allocate 1048577 bytes)
--
Edit bug report at https://bugs.php.net/bug.php?id=75511&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75511&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75511&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75511&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=75511&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=75511&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=75511&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=75511&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=75511&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=75511&r=support
Expected behavior: https://bugs.php.net/fix.php?id=75511&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=75511&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=75511&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=75511&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75511&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=75511&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=75511&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=75511&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75511&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=75511&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=75511&r=mysqlcfg