quot;Transfer-Encoding: chunkedquot; header in PHP(“传输编码:分块PHP中的标头)
问题描述
我想将 Transfer-Encoding: chunked
标头添加到我正在输出的文件(它只是生成纯文本),但是当我添加时:
i want to add Transfer-Encoding: chunked
header to the file that i'm outputing (its just generated plain text), but when i add:
header("Transfer-Encoding: chunked");
flush();
浏览器不想打开文件.
位于 ... 的网页可能是暂时下降或可能已经移动永久转移到一个新的网址.
The webpage at ... might be temporarily down or it may have moved permanently to a new web address.
我需要做什么才能让它工作?
what i need to do for it to work?
推荐答案
您需要在发送的每个块中发送 Content-Length
.查看 Wikipedia 以获得第一印象,分块编码的外观.它不是那么微不足道,而且在许多情况下它的尺寸过大.
You need to send the Content-Length
with every chunk you send. Look at Wikipedia for a first impression, how a chunked encoding looks like. Its not that trivial and in many cases its oversized.
更新:首先,您发送标头,因为它们必须始终在任何内容之前发送(也使用分块编码).然后你发送(对于每个块)大小(十六进制),然后是内容.在每个块之后记住 flush()
.最后,您必须发送一个大小为零的块以确保连接正确关闭.
Update:
First you send the headers, because they must always send before any content (also with chunked encoding). Then you send (for every chunk) the size (in hexadecimal) followed by the content. Remember flush()
after every chunk. At last you must send a zero-size chunk to make sure, that the connection get closed properly.
它没有经过测试,但是是这样的
Its not tested, but something like this
header("Transfer-Encoding: chunked");
echo "5
";
echo "Hello";
echo "
";
flush();
echo "5
";
echo "World";
echo "
";
flush();
echo "0
";
flush();
这篇关于“传输编码:分块"PHP中的标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:“传输编码:分块"PHP中的标头
基础教程推荐
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01