我們正在嘗試使用mod_xsendfile和Apache來有效地處理大文件下載(> 1 GB)。安裝後的配置是這樣的:mod_xsendfile Firefox恢復問題
<IfModule mod_xsendfile.c>
<Directory "/abs_path/to/dl">
XSendFile on
XSendFilePath /abs_path/to/files_dir
</Directory>
</IfModule>
下載腳本確實沒有什麼花哨,只檢查文件是否存在,下載並設置標題爲每文檔,像這樣:
header("Content-type: application/octet-stream");
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
header("X-Sendfile: " . $file);
不間斷下載工作使用我們測試過的任何用戶代理都可以,並且HTTP-Range對除Firefox以外的所有用戶(測試版本27和28)都可以正常工作。 Firefox可以暫停下載,但每次恢復失敗。
這些是活HTTP頭擴展捕獲的HTTP標頭:
初始下載:
http://www.oursite.com/dl/test-xs.php?ID=TestFileID
GET /dl/test-xs.php?ID=TestFileID HTTP/1.1
Host: www.oursite.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip, deflate
Cookie: some cookie string...
Connection: keep-alive
HTTP/1.1 200 OK
Date: Tue, 25 Mar 2014 10:22:46 GMT
Server: Apache
X-Powered-By: PHP/5.3.28
Content-Disposition: attachment; filename="TestFile.ext"
Last-Modified: Sun, 02 Mar 2014 18:20:36 GMT
Content-Length: 84406272
Connection: close
Content-Type: application/octet-stream
...當Firefox的嘗試恢復:
http://www.oursite.com/dl/test-xs.php?ID=TestFileID
GET /dl/test-xs.php?ID=TestFileID HTTP/1.1
Host: www.oursite.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip, deflate
Cookie: same cookie string...
Connection: keep-alive
Range: bytes=11238434-
If-Unmodified-Since: Sun, 02 Mar 2014 18:20:36 GMT
...服務器返回404
HTTP/1.1 404 Not Found
Date: Tue, 25 Mar 2014 10:23:03 GMT
Server: Apache
X-Powered-By: PHP/5.3.28, PHP/5.3.28
Content-Disposition: attachment; filename="TestFile.ext"
X-Sendfile: /abs_path/to/files_dir/TestFile.ext
X-Pingback: http://www.oursite.com/xmlrpc.php
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Cache-Control: no-cache, must-revalidate, max-age=0
Pragma: no-cache
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8
......這明顯會導致Firefox無法恢復下載(現在只能從開始取消並重新啓動)。
考慮一切正常在其他瀏覽器和下載管理器,我們已經試過:
- 有沒有人遇到過類似的行爲?
- 任何人都可以在我們的 下載腳本或配置代碼中解釋或指出它的潛在原因嗎?
編輯:
做更多的一些測試結果證明,問題是下降到恢復下載時If-Unmodified-Since
頭被火狐發送之後。即使此標頭正確設置爲從Apache接收到的Last-Modified
響應標頭的值,服務器也不會因爲某種原因而喜歡它,並以404
作出響應。通過改變從的.htaccess要求剝離If-Unmodified-Since
頭之後:
<Files test-xs.php>
RequestHeader unset If-Unmodified-Since
</Files>
...恢復正常工作無處不在,包括Firefox瀏覽器。
如果要下載的文件同時被修改,但這種方法當然是不正確的,但它爲我們完成了這項工作,因爲我們使用不同的約定來提供同一文件的較新版本。
這顯然更像是一個黑客而不是一個正確的實現,所以不能確定這是否應該被標記爲答案,我將它作爲原始問題的補充。
新的問題出現明顯:
- 有沒有更好的辦法來解決這個問題?
- 這是mod_xsendfile中的錯誤嗎?