x-sendfile alternative for Apache to download huge files with resume-support
I need to programmatically initiate file downloads using PHP along with resume-support
These files are heavy. So IO buffering like below or caching is not an option
$content=file_get_contents($file);
header("Content-type: application/octet-stream");
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
header("Content-Length: ". filesize($file));
echo $content;
The only viable option I found so far is the Apache module X-sendfile. Unfortunately our hosting service won't install mod_xsendfile
- so we are looking for other hosting providers, but that's another story开发者_运维百科.
We are using LAMP and the yii framework. What are possible alternatives?
Will your hosts allow you to install something like Perlbal (http://www.danga.com/perlbal/) as a proxy in front of apache?
Perlbal allows you to offload file-serving to it with a very similar approach to x-sendfile (using X-REPROXY-URL: /path/to/a/local/file.jpg), and it's pretty high-performance. (LiveJournal and Flickr both use(d) it. It would require you to run apache on a different port, though, and run perlbal on port 80, which your hosting provider might not like. Of course, you could do the same thing with something like nginx if you didn't fancy perlbal.
You could emulate that by reading the request headers and output the content in 4kb steps with fopen
, fseek
, fread
and so on. See also the possible request headers here. You should also implement an ETag
to let the client identify that the file has not changed.
精彩评论