A note about my previous comment posted on 16-Aug-2010:
I started running into trouble when I had really large files being sent to clients with really slow download speeds. In those cases, the script would time out and the download would terminate with an incomplete file. I am dead-set against disabling script timeouts - any time that is the solution to a programming problem, you are doing something wrong - so I attempted to scale the timeout based on the size of the file. That ultimately failed though because it was impossible to predict the speed at which the end user would be downloading the file at, so it was really just a best guess so inevitably we still get reports of script timeouts.
Then I stumbled across a fantastic Apache module called mod_xsendfile (https://tn123.org/mod_xsendfile/ (binaries) or https://github.com/nmaier/mod_xsendfile (source)). This module basically monitors the output buffer for the presence of special headers, and when it finds them it triggers apache to send the file on its own, almost as if the user requested the file directly. PHP processing is halted at that point, so no timeout errors regardless of the size of the file or the download speed of the client. And the end client gets the full benefits of Apache sending the file, such as an accurate file size report and download status bar.
The code I finally ended up with is too long to post here, but in general is uses the mod_xsendfile module if it is present, and if not the script falls back to using the code I originally posted. You can find some example code at https://gist.github.com/854168
----
Server IP: 69.147.83.197
Probable Submitter: 96.254.214.139
----
Manual Page -- http://www.php.net/manual/en/function.readfile.php
Edit -- https://master.php.net/note/edit/102759
Del: integrated -- https://master.php.net/note/delete/102759/integrated
Del: useless -- https://master.php.net/note/delete/102759/useless
Del: bad code -- https://master.php.net/note/delete/102759/bad+code
Del: spam -- https://master.php.net/note/delete/102759/spam
Del: non-english -- https://master.php.net/note/delete/102759/non-english
Del: in docs -- https://master.php.net/note/delete/102759/in+docs
Del: other reasons-- https://master.php.net/note/delete/102759
Reject -- https://master.php.net/note/reject/102759
Search -- https://master.php.net/manage/user-notes.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.