Edit report at https://bugs.php.net/bug.php?id=61636&edit=1

 ID:                 61636
 Comment by:         fredericg_99 at yahoo dot fr
 Reported by:        nachnamev2 at t-online dot de
 Summary:            readfile() resp. fpassthru() try to allocate
                     complete file into memory
 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:

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.


Previous Comments:
------------------------------------------------------------------------
[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] nachnamev2 at t-online 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

Reply via email to