Search code examples
phpdownloadvarnishx-sendfile

PHP file download with mod-xsendfile does not download entire file


I am having problem serving downloads from our website. Large files just won't download in full. Download will stop somewhere in between... Example this file (size cca 172MB) won't download in full size (there are other files also).

I switched from entirely PHP-base download script, the one included in Kohana framework:

return download::force($filePath);

to a mod-xsendfile solution. I was reading about the possible problems with PHP based download scripts and large file and cam over mod-xsendfile is the right solution... Well looks like not, I am getting the same result with both techniques. My current download implementation using mod-xsendfile headers like this:

header("X-Sendfile: $filePath");
header("Content-type: application/octet-stream");
header('Content-Disposition: attachment; filename="' . basename($filePath) . '"');

What am I doing wrong?

UPDATE:

I used this HTTP sniffer to check response headers and this is the result if it helps solving this problem.

Status: HTTP/1.1 200 OK
Server: Apache  
Set-Cookie: dewesoftsession=63ms5j67kc231pr4bpm8cmg1f7; expires=Sat, 30-Mar-2013 11:36:59 GMT; path=/   
Expires: Thu, 19 Nov 1981 08:52:00 GMT  
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0   
Pragma: no-cache    
Set-Cookie: dewesoftsession=63ms5j67kc231pr4bpm8cmg1f7; expires=Sat, 30-Mar-2013 11:36:59 GMT; path=/   
Content-Disposition: attachment; filename="DEWESoft_FULL_7_0_5.exe" 
Last-Modified: Mon, 24 Sep 2012 12:50:12 GMT    
ETag: "25814de-ac291e9-4ca7207c7fcd9"   
Content-Type: application/octet-stream  
Content-Length: 180523497   
Date: Sat, 30 Mar 2013 09:37:01 GMT 
X-Varnish: 294312007    
Age: 2  
Via: 1.1 varnish    
Connection: close   
X-Varnish-Cache: MISS

Solution

  • After couple of days we managed to find what cause the problem. Varnish has a start-up parameter called send_timeout which is set to 600s by default. With large file downloads you might run into this timeout which will cause your download to be interrupted.

    So increasing Varnish's send_timeout parameter will help you solve this kind of issue.