ID: 25523
Updated by: [email][/email]
Reported By: psurmano at ucalgary dot ca
Status: Bogus
Bug Type: Output Control
Operating System: Redhat 8.0
PHP Version: 4.3.3
New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the doentation available at
[url][/url] and the instructions on how to report
a bug at [url][/url]

Try a flush() after the echo.

Previous Comments:

[2003-09-13 03:34:55] [email][/email]

Turn off output buffering....


[2003-09-13 01:24:15] psurmano at ucalgary dot ca

When the following code is run in a browser on a very large file php
will first read in the entire file into memory and only afterwards will
it display a download dialog in the browser. This is even though I'm
reading in 8192 bytes at a time.

On a large file this results in a delay of several seconds.

Using readfile() doesn't have this problem but it is unacceptable since
I will need to add code to throttle download speed.

Reproduce code:
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=largeFile");
header("Content-Length: " . filesize("largeFile"));

$handle = fopen ("largeFile", "rb");
do {
$data = fread($handle, 8192);
if (strlen($data) == 0) {
echo $data;
} while(true);
fclose ($handle);

Expected result:
PHP should first show the download dialog and then start reading the
file. This is what happens with readfile()

Actual result:
The file will first get read entirely into memory resulting in a large
delay. Only then is the user prompted with a download dialog.


Edit this bug report at [url][/url]