【发布时间】:2016-07-04 11:35:29
【问题描述】:
我有一个应该永远运行的 codeigniter 控制器方法(无限循环) - 它检查一些数据库并进行一些数据维护。
在某些事件上,我想向浏览器输出(回显)一行,这样我的输出看起来有点像这样:
Service loop started
...task xxx done
...done something else
...found xyz
...task xxx done
...task xxx done
...task xxx done
...done something else
现在 Codeigniter 3 缓冲输出并等待方法完成,然后再将输出发送到浏览器。如何强制 CI3 刷新输出?
这是我的代码(简化):
public function dowork()
{
$counter = 0; // I am using a counter to test this with 1000 loops
while ($counter <= 1000)
{
// do something here....
$this->output->_display(); // this doesn't seem to work
flush(); // I took this from the PHP manual
ob_flush(); // but it doesn't send the output either
$counter++;
}
}
[注意可能需要补充一点,我在 Apache 2.4 / Ubuntu 16.04 LTS 和 PHP 5.6 上运行]
【问题讨论】:
标签: php codeigniter output flush