php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29159 readfile (or fpassthru or even php_stream_passthru) can not output large++ file
Submitted: 2004-07-14 20:18 UTC Modified: 2004-07-14 21:02 UTC
From: victor-php at boivie dot com Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 5.0.0 OS: FreeBSD 4.7
Private report: No CVE-ID: None
 [2004-07-14 20:18 UTC] victor-php at boivie dot com
Description:
------------
victor:~> php -v
PHP 5.0.0RC2 (cgi) (built: Apr 30 2004 08:15:25)

(oh well, this issue still exists in 5.0.0)

victor:~> grep output /usr/local/lib/php.ini
<snip>
output_buffering = 4096
<snip>
output_handler =
<snip>
zlib.output_compression = Off

victor:~> ls -l test.fil 
-rw-r--r--  1 root  wheel  734939136 Oct 14  2003 test.fil

--------------------------------

As the results shows, PHP tries to allocate the whole file in memory which is bad. I thought php_stream_passthru used a small buffer and that it didn't allocate the whole file, but I'm not familiar with the PHP source code. 


Reproduce code:
---------------
<?php
  readfile("test.fil");
?>


Expected result:
----------------
A lot of file data in the browser window (the file contents)

Actual result:
--------------
PHP Fatal error:  Out of memory: cannot allocate 734941208 bytes! in /usr/home/victor/foo.php on line 2
Content-type: text/html
X-Powered-By: PHP/5.0.0RC2

<br />
<b>Fatal error</b>:  Out of memory: cannot allocate 734941208 bytes! in <b>/usr/home/victor/foo.php</b> on line <b>2</b><br />


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-14 21:02 UTC] wez@php.net
When you have output buffering enabled, all your output will be buffered.
Turn off output buffering when you are spitting out large files and your problem will go away.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 16:01:29 2024 UTC