|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37939 script stops if output is large
Submitted: 2006-06-27 21:05 UTC Modified: 2006-07-08 01:00 UTC
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: sviver at vnet dot hu Assigned:
Status: No Feedback Package: Unknown/Other Function
PHP Version: 5.1.4 OS: Windows XP prof.
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2006-06-27 21:05 UTC] sviver at vnet dot hu
I open a file of about 600kb, then loop over it with feof and fread, and echo the read data to the output. In a previous php version (>5, <5.1.4) it returned random characters, but the file size was correct. So I upgraded to 5.1.4 to see whether the problem is still there. With the new version there are no random characters, but the result is much smaller than the original file. Sometimes it's 73728 (=72*1024) bytes, somtimes 24576 (=24*1024), sometimes 98304 (also divisible), sometimes 81920 (also divisible). Etc. The previous version also started producing strange output after reading several block correctly - the new version simply stops reading.
With the previous version the problem disappered if I set the block size to 1*1028. With the new version it persists. There is no error message at the end of the file.

Reproduce code:
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="test.file"');
$packet = 4*1024;
$buff = ''; 
$F = fopen($filename, 'rb');
while (!feof($F)) {
	$buff = fread($F, $packet);
	echo $buff; 

Expected result:
The complete file as a download.

Actual result:
Part of the file. 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-27 21:12 UTC]
Please try using this CVS snapshot:
For Windows:

Honestly saying, I don't understand why you're not using readfile(), as it does exactly what you're doing manually.
 [2006-06-27 21:37 UTC] sviver at vnet dot hu
Hello Tony,

When I wrote the original code about a year ago, readfile seemed to eat up the memory. Anyway, readfile produces the same error.
It's also there with the latest snapshot.
However, setting the block size to one single byte makes it work.

What I found out is that the file can be downloaded with WGET - full filesize, but there is a difference between the two files. Maybe a problem with apache?
 [2006-06-27 21:57 UTC]
Or maybe a problem with your OS.
I've no idea, only you can investigate it since I have serious doubts anyone except you is able to reproduce it.
 [2006-06-27 22:34 UTC] sviver at vnet dot hu

It must be some apache / output problem, as writing $buff into a file works, so data is read correctly. 
I really could have though of trying this on my own. Sorry. I'll invastigate the situation, and tell You, if I find anything that's useful to know for others too.

Thanks, have a nice day.
 [2006-06-27 22:44 UTC]
You can also try another browser.
Anyway, it's likely not PHP problem, so I'm marking this as bogus.
Feel free to reopen it if/when you have any additional information.
 [2006-06-30 16:25 UTC] sviver at vnet dot hu
I investigated the problem, and also found other users reporting the same error for prevoius releases. See bug #14348 as an example. I get exactly the same symptoms. It's not related to the filesystem as I thought before. Ouputting random characters also causes the error. There is absolutely no error message in the apache logs.
I reinstalled windows, but it stayed. The strange thing is that formerly as far as I can remember it used to work without any problems. Using the apache -X flag as suggested in the other bug report does not help either. Plain text files can be donwloaded, so I think this is not an apache-only problem. 
Is there any way I can somehow get more debug information out of php?
 [2006-06-30 16:55 UTC] sviver at vnet dot hu
Setting output_buffering=Off AND implicit_flush=On solves the problem in my case as well (but decreases performance of course).
 [2006-06-30 22:03 UTC]
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at

If you can provide more information, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PHP.

 [2006-07-08 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, 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-2023 The PHP Group
All rights reserved.
Last updated: Tue Mar 21 15:03:42 2023 UTC