首页 / PHP / 使用PHP生成HTTP 206内容响应
使用PHP生成HTTP 206内容响应
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了使用PHP生成HTTP 206内容响应,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2432字,纯文字阅读大概需要4分钟。
内容图文
![使用PHP生成HTTP 206内容响应](/upload/InfoBanner/zyjiaocheng/659/3da19e7e52a8469bb13d1ff7c381a429.jpg)
我正在使用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.
解决方法:
尝试设置内容范围:50-6642902 / 6642903
根据http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
内容总结
以上是互联网集市为您收集整理的使用PHP生成HTTP 206内容响应全部内容,希望文章能够帮你解决使用PHP生成HTTP 206内容响应所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。