2016-02-28 41 views
0

是否有限制Xsendfile下載速度的選項? 我要讓限速&連接限制通過Xsendfile限制速度在Xsendfile的下載文件中

Xsendfile之前生效下載(FREAD())我用這個代碼做限速:

if ($speed > 0 && ($this->bandwidth > $speed*$packet*1024)) 
      { 
       sleep(1); 
       $packet++; 
      } 

但Xsendfile我無法控制速度。在這種辦法 !

此外,我能夠通過Accept-Ranges標題來激活或停用resume,但我無法在xsendfile中執行此操作!

回答

0

X-Sendfile將數據傳輸卸載到Linux內核,Linux內核將數據從文件直接發送到網絡。這避免了必須將文件的數據複製到用戶空間內存中,因此使用較少的CPU。由於數據沒有通過任何用戶空間進程,因此無法手動調整它。

您可以通過流量整形來限制帶寬,但這是一個系統配置問題,因此在這裏是無關緊要的。在這方面有很多關於serverfault的問題,例如https://serverfault.com/questions/174010/limit-network-bandwith-for-an-iphttps://serverfault.com/questions/191560/how-can-i-do-traffic-shaping-in-linux-by-ip

至於文件範圍,mod_xsendfile supposedly already takes care of that(參見「優點」)。

+0

所以沒有辦法通過PHP來處理它? – jasone

+0

沒有。當你使用'sendfile'時,用戶空間進程不知道如何傳輸數據 – Joni