使用mod-xsendfile下载PHP文件不会下载整个文件


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

我有问题服务下载从我们的网站。大文件无法完整下载。下载将在两者之间的某个地方停止…例如,此文件(大小为cca 172MB)无法完整下载(也有其他文件)。

我从完全基于php的下载脚本切换到Kohana框架中包含的脚本:

return download::force($filePath);

到mod-xsendfile解决方案。我正在阅读关于基于PHP的下载脚本和大文件可能存在的问题,而mod-xsendfile是正确的解决方案…看起来不是,两种方法得到的结果是一样的。我目前使用mod-xsendfile头的下载实现如下:

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

我做错了什么?

更新:

我使用这个HTTP嗅探器来检查响应头,这是如果它有助于解决这个问题的结果。

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

几天后,我们设法找到了问题的原因。Varnish有一个名为send_timeout的启动参数,默认设置为600s。对于大文件下载,您可能会遇到此超时,这将导致下载中断。

所以增加Varnish的send_timeout参数可以帮助你解决这类问题。