PHP 刷新所有级别的输出缓冲
我正在尝试实现一个简单的 Http Response 类,该类实现 Http Streaming (或 Chunked-Encoding)。为了实现这一点,我需要在 php.ini 中设置 output_buffering = Off
,并以一定的时间间隔刷新输出。
PHP 自动很好地完成了这项工作——除了实际的刷新机制。我已经让它工作了,但我不确定它是否太过分了。我想知道如何立即刷新每个级别的输出缓冲,而不调用十亿个函数(我不确定哪些函数在哪些环境/哪些场景中是多余的)。
while (ob_get_level())
{
ob_end_flush();
}
// print the buffer
flush();
ob_flush();
这是否太过分了?
I'm trying to implement a simple Http Response class that implements Http Streaming (or Chunked-Encoding). For this to be possible, I need to set output_buffering = Off
in the php.ini, and flush the output at certain intervals.
PHP does a good job of this automatically - except for the actual flushing mechanism. I've gotten it to work, but I'm not sure if it's overboard. I want to know how to flush each level of output buffering at once, without calling a billion functions (I'm not sure which ones are redundant on which environments / in which scenarios).
while (ob_get_level())
{
ob_end_flush();
}
// print the buffer
flush();
ob_flush();
Is this overkill?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要
ob_flush()
和ob_end_flush()
。你的 while 循环就足够了。您还应该查看: http://us.php.net /manual/en/function.ob-implicit-flush.php
您是否需要在
ob_end_flush()
之后使用flush()
取决于您如何设置此函数。You don't need
ob_flush()
andob_end_flush()
. Your while loop is sufficient.You should also look at: http://us.php.net/manual/en/function.ob-implicit-flush.php
Your need for
flush()
afterob_end_flush()
depends on how you set this function.