|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #19886 readfile, fread, fpassthru won't work with large files!!!
Submitted: 2002-10-13 09:08 UTC Modified: 2002-11-16 01:00 UTC
Avg. Score:4.5 ± 0.8
Reproduced:5 of 5 (100.0%)
Same Version:2 (40.0%)
Same OS:1 (20.0%)
From: Assigned:
Status: No Feedback Package: Filesystem function related
PHP Version: 4CVS-2002-10-13 OS: Windows, any Version
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2002-10-13 09:08 UTC]
Environment: Windows
WebServer: Microweb (CD-WebServer)
PHP-Version: Latest CVS and 4.2.4-dev
PHP is installed as CGI

In a frameset-environment, PHP hangs while outputting large PDF-Files. The Frameset consists of three Frames. Every Frame is PHP-generated. One functions as "PDF-Passthrough".

All works fine, if the Passthrough-File is smaller than approx. 100k. Files >100k make the system hang.

Calling the passthrough-script directly (w/o frameset) causes no problems.

There is no difference between using readfile, fpassthru, or fread.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-10-13 09:10 UTC]
Note: Calling sleep(5) before dumping the PDF solves the problem, so I think the bug is related to a memory management/multithreading problem...
 [2002-10-13 09:37 UTC]
did you checked if php_stream_read() was returning the right filesize value? that was the first bug.
 [2002-10-13 10:02 UTC]
Can you reduce this to the simplest combination of scripts?
(That don't use sessions).
 [2002-10-13 10:16 UTC]
@wez: These scripts don't use sessions. They run of a CD in a single-user-environment.

@nicos: Calling the "passthrough"-script directly works without errors. But calling it in an frameset (together with two other scripts) crashes when outputting a file > 100k,

The php_stream_read() returns the correct filesize.
The fact, that the parrallel execution of three scripts of one handles a big file may be the source of the problem.

There are no write-accesses. Only Read-Accesses to small config-files.

Removing the "big-files-passthrough" let the scripts run properly.
 [2002-10-13 10:19 UTC]
The following snippets illustrate the environment


header("Content-type: application/pdf\n");

echo "Something";

echo "else";
 [2002-10-13 10:22 UTC]
That last comment should let us open it back.

Removing the "big-files-passthrough" let the scripts run properly.

@Wez: can you check it? may be its because of the position of the stream at the end of the execution of the first checksize?
 [2002-10-13 10:30 UTC]
In addition

// Adding sleep(5) will solve the problem the first time a
// >100k File is called. The next output of a >100k File
// will crash again...
header("Content-type: application/pdf\n");
 [2002-10-13 10:40 UTC]
May be its because that the stream hasn't enough time to get its new position. I didn't read streams.c/h well enough too.
 [2002-10-13 17:21 UTC]
Did this work in any previous versions of PHP?
Is it stricly win32 thing? Does this workin in e.g. Linux?

 [2002-10-13 19:06 UTC]
I just fixed (I hope) a socket-shutdown bug (#16114).
The interesting thing is that this is only to do with
writes to sockets opened by streams (so it should not
affect PHP output).

It might be that the Microweb server also has a similar
bug, or that it has some other threading issue.

It doesn't make sense for this to be related solely to
streams, as they aren't time-dependent, and they are
certainly not dependent on other PHP processes.

Can you try reproducing the problem using Apache, PWS
or IIS?
Can anyone reproduce this on another platform?

 [2002-10-29 06:55 UTC] selfman at lasercat dot de
I have a simmilar problem on windows 2000 Server with IIS4.
I use this script (just a part):
header("Content-type: Download");
header("Content-Disposition: attachment; filename=".$Data->SWFileName);
$fp = fopen ($GLOBALS['FileLocation'].$Data->SWFileName, "rb");

The problem is that on our development machine (Linux) everything works like a charm, but on our "Production" server with Win2k Server & IIS not.
There is a small JavaScript which calls the file sending script usimg window.location='getfile.php?fileid=56'

The problem place is that the time between request and displaying the "save" dialog is very large. (1-2 minutes or so) I can't get it to execute faster.
I will try to use the fread().


 [2002-10-29 09:10 UTC]
As a sanity check, you're not using output buffering or ob_gzhandler, or zlib.output_compression or transparent
SID/session rewriting, are you?
 [2002-10-29 16:14 UTC]
For me, I dont have output buffering or ob_gzhandler,
or zlib.output_compression or transparent SID/session rewriting enabled. I tested even a max execution time of a day.
 [2002-10-29 19:13 UTC]
and did you try the most recent snapshot as I suggested
on the 13 Oct?
And could you reproduce the issue using a different web server?
 [2002-10-31 04:34 UTC] selfman at lasercat dot de
None of them has been used (output buffering or ob_gzhandler, or zlib.output_compression or transparent SID/session rewriting). The fopen() -> $val = fread()-> echo $val worked fine. The response was much quicker.
Never minad... I have solved the problem otherwise. And the data have moved to a differen server with higher capacity.

Regards SelfMan
 [2002-10-31 05:17 UTC] harbater at teamgenesis dot com
I'm experiencing something similar on Linux Apache using Version 4.1.2.  As far as I know it worked before I upgraded from an earlier version. 

My code looks like this:

$fp  = fopen($file, "r");


$contents = fread($fp, $size);

Header("Content-Type: $type");
Header("Content-Disposition: attachment; filename=$downloadname");
header("Content-Length: $size");
header("Content-Transfer-Encoding: binary");
echo $contents;

filesize() is reporting the size properly.  The code works perfectly for smaller files, but the fread() fails for files larger than 19 MB or so and I got a page cannot be displayed error.  All the files being downloaded are PDF files.
 [2002-10-31 07:01 UTC]
The problem can be reproduced using Apache/Win32 using the script posted at 13 Oct 10:19am.

I tried the newest snapshot (31-Oct-2002 03:28). Furthermore, the previous snaps and different release versions (>4.2.2) don't work. I deleted versions < 4.2.1, so I can't test them any more.

 [2002-10-31 07:59 UTC]
Thank you for this bug report. To properly diagnose the problem, we
need a backtrace to see what is happening behind the scenes. To
find out how to generate a backtrace, please read

Once you have generated a backtrace, please submit it to this bug
report and change the status back to "Open". Thank you for helping
us make PHP better.

 [2002-11-16 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over 2 weeks, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Dec 05 09:03:36 2021 UTC