Home > Article > Backend Development > Understand the difference between ob_flush and flush in PHP
This article will introduce to you the difference between ob_flush and flush. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
The description of ob_flush/flush in the manual is that it refreshes the output buffer and needs to be used in conjunction, so it will cause confusion to many people...
In fact, they operate on different objects. In some cases, flush does nothing at all.
ob_* series of functions operate the output buffer of PHP itself.
So, ob_flush It is to refresh PHP's own buffer.
And flush, strictly speaking, this only has an actual effect when PHP is installed as an Apache Module (handler or filter). It is to refresh the WebServer (can I think it refers specifically to the buffer of apache).
Under sapi
of apache module
, flush
will be called by calling sapi_module
's flush
member function pointer, indirectly calls apache
's api: ap_rflush
refreshes apache
's output buffer, of course, the manual also Having said that, there are some other modules of Apache that may change the result of this action..
Some Apache modules, such as mod_gzip, may perform output caching by themselves, which will cause the flush() function to be generated. The results are not sent to the client browser immediately.
Even the browser will cache the received content before displaying it. For example, the Netscape browser caches content until it receives a newline or the beginning of an html tag, and does not display an entire table until it receives a tag.
Some versions of Microsoft Internet Explorer will only begin to display the page after receiving 256 bytes, so some additional spaces must be sent to allow these browsers to display the page content.
So, the correct order to use the two is. First ob_flush, then flush,
Of course, under other sapi, you can not call flush, just to ensure that your code For portability, it is recommended to use it together.
This article is reproduced from: https://blog.csdn.net/qq_28602957/article/details/66973431
Recommended: PHP video tutorial
The above is the detailed content of Understand the difference between ob_flush and flush in PHP. For more information, please follow other related articles on the PHP Chinese website!