Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

x-sendfile alternative for Apache to download huge files with resume-support

Tags:

php

apache

yii

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?

like image 249
S B Avatar asked Aug 25 '11 09:08

S B


2 Answers

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.

like image 129
Chris May Avatar answered Sep 19 '22 05:09

Chris May


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.

like image 45
rekire Avatar answered Sep 20 '22 05:09

rekire