PHP缓冲区ob_flush()与flush() [英] PHP buffer ob_flush() vs. flush()
问题描述
ob_flush()
和flush()
有什么区别?为什么必须同时调用两者?
What's the difference between ob_flush()
and flush()
and why must I call both?
此函数将发送输出缓冲区的内容(如果有).
This function will send the contents of the output buffer (if any).
刷新PHP的写缓冲区以及PHP正在使用的任何后端(CGI,Web服务器等).
Flushes the write buffers of PHP and whatever backend PHP is using (CGI, a web server, etc).
但是,它继续说:
[it]可能无法覆盖您的Web服务器的缓冲方案……
[it] may not be able to override the buffering scheme of your web server…
所以,在我看来,我可以一直使用ob_flush()
.但是,当我这样做时,会得到奇怪的结果.有人可以简单地解释一下这是怎么回事吗?
So, seems to me that I could just use ob_flush()
all of the time. However, I get strange results when I do that. Could someone explain in simple terms what's going on here?
推荐答案
ob_flush
发送应用程序启动的缓冲区.任何PHP脚本中都可能有多个嵌套的ob_start()
. ob_flush
将当前内容传递到上层.
ob_flush
sends an application-initiated buffer. There may be multiple nested ob_start()
's in any PHP script. ob_flush
passes the current content to the upper layer.
PHP本身(可能会自行决定)是否缓冲输出.这取决于后端.但是通常FastCGI
自己有一个套接字缓冲区.因此,还需要调用flush()
,以将当前内容发送到Web服务器.
PHP itself might (at its own discretion) buffer output. This depends on the back-end. But usually FastCGI
has a socket buffer on its own. Therefore flush()
needs to be invoked as well to send the current content to the web server.
现在,Web服务器本身可能实现了另一种缓冲方案(mod_deflate
或内容过滤器),您对此没有影响.但这很少见,因为需要对其进行专门配置.
And now the web server might itself implement another buffering scheme (mod_deflate
or content filter), which you have no influence over. But this is seldom, as it needs to be configured specifically.
无论如何,请同时使用两者.
Anyway, use both.
这篇关于PHP缓冲区ob_flush()与flush()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!