Home>Article>Backend Development> Understand the difference between ob_flush and flush in PHP

Understand the difference between ob_flush and flush in PHP

青灯夜游
青灯夜游 forward
2020-03-31 16:39:02 2802browse

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.

Understand the difference between ob_flush and flush in PHP

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).

Undersapiofapache module,flushwill be called by callingsapi_module'sflushmember function pointer, indirectly callsapache'sapi: ap_rflushrefreshesapache'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 atag.

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!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete