|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-09-02 08:25 UTC] derick@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 03 12:00:01 2025 UTC |
Description: ------------ If output buffering is used and a large file is opened and the resulting handle is passed to fpassthru, memory exhaustion occurs. The optimization in _php_stream_passthru mmaps the entire file into the address space. During the PHPWRITE call sequence, an output buffer is allocated the size of the mmap'ed file. If the file is large, a large allocation occurs. Semantically, fpassthru should not cause memory exhaustion. Generally, large writes to buffered IO should generate several flushes to the underlying IO device instead of allocating one large buffer to store the contents. This limits the applications of fpassthru to where the file size is known before hand and where the size is smaller than memory_limit or available memory. This was earlier reported as #20772 Reproduce code: --------------- Create a file larger than memory_limit or available memory memory_limit = 8M dd if=/dev/zero of=bigfile bs=1M count=128 <?php $fp = fopen('./bigfile','r'); fpassthru($fp); ?> Expected result: ---------------- The entire output of the file Actual result: -------------- No output PHP Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 134213632 bytes) in /home/tcarroll/public_html/passthru.php on line 14