Forum Moderators: coopster

Message Too Old, No Replies

PHP readfile

         

jackvull

2:08 pm on Jul 26, 2005 (gmt 0)

10+ Year Member



I have a script on my web server which gets files and forces the save dialogue to the user by using header information and readfile().

All works correctly but it seems to be particularly slow on files that are over 30Mb. A file of 5Mb has the save dialogue displayed in a second or or quicker but for a file of 60Mb it seems to take up to 10seconds, which is not very good for the user.

Do you know of anything within the readfile() function that could cause this?

dmorison

2:16 pm on Jul 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's got to be down to some buffering going on someplace or other, and likely to be difficult to track down without going into PHP internals.

If the objective (and quite rightly so) is to improve the user experience, regardless of whether or not it actually makes any difference overall, you might want to try a combination of fread() [uk.php.net],flush() [uk.php.net] and fpassthru() [uk.php.net]

Something like:


$fp = fopen("/path/to/file","r");

echo(fread($fp,2048)); // get the first 2K out the door that should trigger the browser's download prompt

flush();

fpassthru($fp);

fclose($fp);

exit();

That's off the top of my head so I can't confirm that this will provoke the download dialogue but it may help...!

jackvull

1:49 pm on Jul 27, 2005 (gmt 0)

10+ Year Member



Hi
That works, in that the save dialogue is still presented and the file can be downloaded, but there doesn't seem to be any effect on the speed.
Files less than 10Mb show the save dialogue almost immediately. A 60Mb takes 10secs.
Any ideas on what else it could be?

By the way, how would the buffering affect this?

Thanks...

jackvull

9:57 am on Jul 28, 2005 (gmt 0)

10+ Year Member



My apologies. Tried it on a different computer and it's lots quicker!
Thanks.