3

使用 PHP 我正在尝试发送 HTTP 206 内容。但不知何故,在收到标头后,客户端报告关闭连接,即使我已经确认内容正在服务器上发送。

我认为这与标题或类似的设置有关。顶层代码是:

  $headers['content-length'] = $range['end']-$range['start']+1;

  header('HTTP/1.1 206 Partial Content');
  header("Pragma: {$headers['pragma']}");
  header("Cache-Control: {$headers['cache-control']}");
  header("Content-type: {$headers['content-type']}");
  header("Content-Disposition: {$headers['content-disposition']}; filename=\"{$headers['filename']}\"");
  header("Content-range: {$range['start']}-{$range['end']}/{$reqFile['size']}");
  header("Content-length: {$headers['content-length']}");

  outputFileRange($reqFile['handle'], $range['start'], $range['end']);

WGET 输出

当我尝试通过 wget 获取时:

$ wget -t 1 -d -SO /dev/null --header="X-Backend-Port: 80" --header="Range: bytes=50-" http://1.2.3.4/download/123.ogv

我得到以下信息:

Setting --server-response (serverresponse) to 1
Setting --output-document (outputdocument) to /dev/null
Setting --header (header) to X-Backend-Port: 80
Setting --header (header) to Range: bytes=50-
DEBUG output created by Wget 1.13.4 on linux-gnu.

URI encoding = `UTF-8'
--2013-10-18 11:05:36--  http://1.2.3.4/download/123.ogv
Connecting to 1.2.3.4:80... connected.
Created socket 4.
Releasing 0x0855da38 (new refcount 0).
Deleting unused 0x0855da38.

---request begin---
GET /download/123.ogv HTTP/1.1
User-Agent: Wget/1.13.4 (linux-gnu)
Accept: */*
Host: 1.2.3.4
Connection: Keep-Alive
X-Backend-Port: 80
Range: bytes=50-

---request end---
HTTP request sent, awaiting response... 
---response begin---
HTTP/1.1 206 Partial Content
Server: nginx/0.7.67
Date: Fri, 18 Oct 2013 07:05:36 GMT
Content-Type: application/octet-stream
Connection: keep-alive
X-Powered-By: PHP/5.3.3-7+squeeze17
Pragma: 
Cache-Control: 
Content-Disposition: attachment; filename="123.ogv"
Content-range: 50-6642903/6642903
Content-length: 6642854

---response end---

  HTTP/1.1 206 Partial Content
  Server: nginx/0.7.67
  Date: Fri, 18 Oct 2013 07:05:36 GMT
  Content-Type: application/octet-stream
  Connection: keep-alive
  X-Powered-By: PHP/5.3.3-7+squeeze17
  Pragma: 
  Cache-Control: 
  Content-Disposition: attachment; filename="123.ogv"
  Content-range: 50-6642903/6642903
  Content-length: 6642854
Registered socket 4 for persistent reuse.
Disabling further reuse of socket 4.
Closed fd 4


Giving up.
4

1 回答 1

3

尝试根据http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html设置 Content-range: 50-6642902/6642903

于 2013-10-18T07:24:50.040 回答