下载大文件 不经过php 直接让apache发送文件给客户端 mod_xsendfile
生活随笔
收集整理的這篇文章主要介紹了
下载大文件 不经过php 直接让apache发送文件给客户端 mod_xsendfile
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
最近有一個新的需求
? 提供用戶下載系統的鏡像文件(1.6G的一個zip文件)
1 首先用了很挫的php讀取文件的方式
? 一下載整個server就blocked在那邊
2 去看了下range
? 發現它是用來實現斷點續傳的,也可以把大文件分成好幾段傳
似乎可以解決問題 試了下 還是不太好用
3 最后嘗試了mod_xsendfile
? 很好地解決了這個問題
1) 安裝apache模塊擴展工具apxs
sudo apt-get install apache2-dev2) 下載源碼 mod_xsendfile.c
https://tn123.org/mod_xsendfile/
3) 編譯源碼
4) 開啟
sudo a2enmod xsendfile5) 指定文件路徑
<Directory /var/www/somesite/>XSendFilePath /var/www/shared </Directory>6)重啟apache
sudo /etc/init.d/apache2 restart // 或者 sudo service apache2 restart7)輸出case:
header("X-Sendfile: $path_to_somefile");header("Content-Type: application/octet-stream");header("Content-Disposition: attachment; filename=\"$somefile\"");exit;?
?
ps:后知后覺的發現 這里面應該是兩個問題
1)php讀取和輸出大文件 太占內存 (用range分割文件進行讀取發送)
2)php的阻塞問題 (下載前把session關掉應該就可以解決阻塞的問題 session_write_close )
等有空了 再試下這個
不過從感覺上 覺得x-sendfile應該更好用
?
參考資料:https://tn123.org/mod_xsendfile/
?
轉載于:https://www.cnblogs.com/ateoa/p/4250484.html
總結
以上是生活随笔為你收集整理的下载大文件 不经过php 直接让apache发送文件给客户端 mod_xsendfile的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: IIS发布站点错误收集(持续更新)
- 下一篇: poj 3082多边形相交 'Roid