Edit report at https://bugs.php.net/bug.php?id=61636&edit=1
ID: 61636
User updated by: kontrollfreak at arcor dot de
Reported by: kontrollfreak at arcor dot de
Summary: readfile() resp. fpassthru() try to allocate
complete file into memory
-Status: Feedback
+Status: Open
Type: Bug
Package: Apache related
Operating System: Windows XP SP3
PHP Version: master-Git-2012-04-05 (snap)
Block user comment: N
Private report: N
New Comment:
In reply to [2013-04-14 12:55 UTC] [email protected]:
During the test output buffering was disabled by the following snippet.
Disable output buffering:
-------------------------
<?php
while (ob_get_level())
ob_end_flush();
?>
Previous Comments:
------------------------------------------------------------------------
[2013-04-14 12:55:29] [email protected]
Be sure to disable output buffering, see http://www.php.net/readfile
------------------------------------------------------------------------
[2013-04-14 11:18:29] kontrollfreak at arcor dot de
(Windows only)
kv3981 at gmail dot com's solution works as long as the transfer does not take
longer than max_execution_time.
------------------------------------------------------------------------
[2013-02-10 20:00:53] fredericg_99 at yahoo dot fr
I can confirm that the problem exists on PHP 5.3.16.
However, the problem does not appear for every files, but once it appears on a
file, it applies for every attempts on that file (and not necessarily for the
others).
The proposed workaround works.
------------------------------------------------------------------------
[2012-11-09 23:52:20] kv3981 at gmail dot com
Same issue on
--------------
- Debian Squeeze 6.0.6
- PHP 5.3.3-7+squeeze14
- Default php.ini, with memory_limit 128M 128M
Workaround
-----------
<?php
// Reads large file, fixes: https://bugs.php.net/bug.php?id=61636
function readlargefile($fullfile) {
$fp = fopen($fullfile, 'rb');
if ($fp) {
while (!feof($fp)) {
print(fread($fp, 2097152));
}
fclose($fp);
}
}
?>
------------------------------------------------------------------------
[2012-04-05 12:31:13] kontrollfreak at arcor dot de
Description:
------------
Tested on:
- PHP 5.5.0dev (r324251) as Apache 2.2 module
- Apache 2.2.22
This bug applies to the Apache module on Windows only. The cgi version does not
show this behavior.
I narrowed it down to PHP 5.2.10. Before that version the test script runs
without error.
Test script:
---------------
<?php
//test.bin has 200 MB
readfile('test.bin');
?>
Expected result:
----------------
No error
Actual result:
--------------
Immediate result (doesn't even begin to load the file):
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to
allocate 209719296 bytes) in C:*\readfile.php on line 4
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=61636&edit=1