亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么在使用 HTTP Accept-Ranges 提供大文件時未滿足 PHP

為什么在使用 HTTP Accept-Ranges 提供大文件時未滿足 PHP

PHP
拉丁的傳說 2024-01-19 10:07:42
以下腳本用于(評估)向客戶端發送大型視頻文件。它在后面使用http headers Accept-Ranges。即使在處理大文件(> 2 GB)時,也不會滿足 PHP 限制(為了測試,我設置了較小的值,例如 memory_limit=16MB 和 max_execution_time=30)。我想“理解”后面的上下文,因為 chrome 僅顯示一個(部分)請求,每隔幾秒增加“時間”和“大小”,盡管 apache 日志文件中沒有顯示其他請求。$file = './videos/' . basename($_GET['video']);if(!file_exists($file)) return; $fp = @fopen($file, 'rb');      $size   = filesize($file); // File size $length = $size;           // Content length$start  = 0;               // Start byte$end    = $size - 1;       // End byte  header('Content-type: video/mp4');header("Accept-Ranges: 0-$length");header("Accept-Ranges: bytes"); if (isset($_SERVER['HTTP_RANGE'])) {    $c_start = $start;                  $c_end   = $end;                    list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);    if (strpos($range, ',') !== false) {        header('HTTP/1.1 416 Requested Range Not Satisfiable');        header("Content-Range: bytes $start-$end/$size");        exit;          }                  if ($range == '-') {                    $c_start = $size - substr($range, 1);    }else{                 $range  = explode('-', $range);         $c_start = $range[0];                   $c_end   = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $size;    }    $c_end = ($c_end > $end) ? $end : $c_end;    if ($c_start > $c_end || $c_start > $size - 1 || $c_end >= $size) {         header('HTTP/1.1 416 Requested Range Not Satisfiable');        header("Content-Range: bytes $start-$end/$size");        exit;          }    $start  = $c_start;                 $end    = $c_end;                   $length = $end - $start + 1;        fseek($fp, $start);                 header('HTTP/1.1 206 Partial Content');}   
查看完整描述

1 回答

?
素胚勾勒不出你

TA貢獻1827條經驗 獲得超9個贊

curl通過在不使用任何范圍標頭的情況下通過命令行請求腳本,同時擁有max_execution_time=1并提供 2.893 GB 文件,找出了更多詳細信息。


在同一臺機器上(在 7 秒和 678 MB 處中止):


% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed  

23 2893M   23  678M    0     0  92.5M      0  0:00:31  0:00:07  0:00:24     0 

curl: (18) transfer closed with 2322893144 bytes remaining to read

在帶寬較低的外國機器上(在 49 秒和 599 MB 處中止):


% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed  

20 2893M   20  599M    0     0  12.1M      0  0:03:58  0:00:49  0:03:09 10284 

curl: (18) transfer closed with 2404747608 bytes remaining to read

就此而言,amax_execution_time=30在這種情況下并不是真正的“小”,因為它允許傳輸估計約 30 * 600 MB(= 18 GB?。???蛻舳说恼埱蟪掷m時間與服務器端的執行時間完全無關。


事實上,當從 html5 視頻對象中調用腳本時,會完成多個部分請求max_execution_time=1(在帶寬更低的桌面客戶端上,每個請求大約需要 14 分鐘,直到中止并傳輸大約 500 MB)。


最后,我很困惑,因為客戶端請求持續時間和服務器端執行時間之間存在巨大差異。


查看完整回答
反對 回復 2024-01-19
  • 1 回答
  • 0 關注
  • 171 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號