|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2017-11-13 01:10 UTC] rasmus@php.net
-Status: Open
+Status: Verified
[2017-11-13 01:10 UTC] rasmus@php.net
[2017-11-13 03:14 UTC] laruence@php.net
[2017-11-13 03:14 UTC] laruence@php.net
-Status: Verified
+Status: Closed
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 12:00:01 2025 UTC |
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)