这已经有点模糊了...如果你不介意大块,(0x1000个八位字节左右),那么是的,PHP会制作它们。
<?php
while (true) {
# output data
flush()
usleep(pow(2,18));
}
?>
PHP将生成编号部分等。
如果你想发送微小的块,就像你可能用AJAX客户端做的那样......好吧,我已经将OP问题与一些关于 PHP.NET 的研究结合起来,看起来他确实是在做一件好事。
$ echo -en “GET /chunked/ HTTP/1.1\r\nHost: ec\r\n\r\n” |nc 本地主机 80
HTTP/1.1 200 OK
Date: Wed, 23 May 2012 13:03:01 GMT
Server: Apache/2.2.9 (Debian) PHP/5.3.5-1 with Suhosin-Patch mod_ssl/2.2.9 OpenSSL/0.9.8o
X-Powered-By: PHP/5.3.5-1
Transfer-encoding: chunked
Content-Type: text/html
14
Teachers have class.
50
We secure our friends not by accepting favors but by doing them.
-- Thucydides
48
Vulcans never bluff.
-- Spock, "The Doomsday Machine", stardate 4202.1
31
All kings is mostly rapscallions.
-- Mark Twain
41
Reappraisal, n.:
An abrupt change of mind after being found out.
49
He who knows, does not speak. He who speaks, does not know.
-- Lao Tsu
它最终是否会挤出它自己的(不正确的)块计数,还有待观察......但我没有看到任何迹象。
<?php
header("Transfer-encoding: chunked");
@apache_setenv('no-gzip', 1);
@ini_set('zlib.output_compression', 0);
@ini_set('implicit_flush', 1);
for ($i = 0; $i < ob_get_level(); $i++) ob_end_flush();
ob_implicit_flush(1); flush();
function dump_chunk($chunk)
{
printf("%x\r\n%s\r\n", strlen($chunk), $chunk);
flush();
}
for (;;) {
$output = array();
exec("/usr/games/fortune", $output);
dump_chunk(implode("\n", $output));
usleep(pow(2,18));
}
?>