Home >Backend Development >PHP Tutorial >In-depth understanding of the difference between ob_flush and flush in php

In-depth understanding of the difference between ob_flush and flush in php

黄舟
黄舟Original
2017-08-10 11:20:591543browse


The description of ob_flush/flush in the manual is to refresh the output buffer, and it also needs to be used in conjunction, so it will cause confusion to many people...

In fact, they The two operation objects are different. In some cases, flush does nothing at all.

ob_* series of functions operate the output buffer of PHP itself.

So, ob_flush refreshes PHP Its own buffer.

And flush, strictly speaking, this only has an actual effect when PHP is installed as apache Module (handler or filter). It refreshes the WebServer (can be considered specifically apache) buffer.

Under sapi of apache module, flush will be # by calling sapi_module ##flush Member function pointer, indirectly calls the api of apache: ap_rflush refreshes the output buffer of apache, of course the manual also says, There are some other modules of apache that may change the result of this action..

有些Apache的模块,比如mod_gzip,可能自己进行输出缓存,
这将导致flush()函数产生的结果不会立即被发送到客户端浏览器。 

甚至浏览器也会在显示之前,缓存接收到的内容。例如 Netscape
浏览器会在接受到换行或 html 标记的开头之前缓存内容,并且在
接受到 </table> 标记之前,不会显示出整个表格。 

一些版本的 Microsoft Internet Explorer 只有当接受到的256个
字节以后才开始显示该页面,所以必须发送一些额外的空格来让这
些浏览器显示页面内容。

So, the correct order to use the two is. First ob_flush, then flush,

Of course, in other sapi You can do this without calling flush, but in order to ensure the portability of your code, it is recommended to use it together.

The above is the detailed content of In-depth understanding of the difference between ob_flush and flush in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn