note 102759 added to function.readfile
| From: | chrisbloom7 at gmail dot com | Date: | Fri, 04 Mar 2011 04:39:32 +0000 |
| Subject: | note 102759 added to function.readfile | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-177551@lists.php.net to get a copy of this message | ||
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