【发布时间】:2016-10-15 05:26:58
【问题描述】:
我在循环中有一些长时间的处理,并希望连续输出进度。
while (true)
{
$percents = $do_my_stuff();
echo $percents;
$this->log($percents);
}
我尝试了很多技巧,但仍然没有运气
ini_set('output_buffering', 'off');
ini_set('zlib.output_compression', false);
while (@ob_end_flush());
ini_set('implicit_flush', true);
ob_implicit_flush(true);
flush() 在每个循环中
循环进入
$this->response->body(function () { /* loop with echo here */ }
但脚本完成后浏览器仍会显示所有数据一次。响应头:
HTTP/1.1 200 OK
Host: localhost:8765
Connection: close
X-Powered-By: PHP/5.6.20
Content-type: text/html; charset=UTF-8
PHP 5.6,使用./bin/cake server 的内置服务器,CakePHP 3
我该怎么做?我希望我的用户看到操作的百分比,因为它可以运行很长时间。
【问题讨论】:
标签: php cakephp stream cakephp-3.x