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...
Actually, they operate on different objects. In some cases, flush does nothing at all..
The ob_* series of functions operate the output buffer of PHP itself.
So, ob_flush is to refresh PHP's own buffer.
Strictly speaking, flush only has an actual effect when PHP is installed as an apache Module (handler or filter). It refreshes the buffer of the WebServer (which can be considered specifically apache).
Under the sapi of the apache module, flush will indirectly call the apache api by calling the flush member function pointer of sapi_module: ap_rflush refreshes the output buffer of apache. Of course, the manual also says that there are some other modules of apache. may change the outcome of this action..
Some Apache modules, such as mod_gzip, may perform output caching by themselves, which will cause the results generated by the flush() function to not be sent to the client browser immediately. Even browsers cache received content before displaying it. For example, the Netscape browser caches content until it receives a line break 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 start displaying the page after receiving 256 bytes, so some extra spaces must be sent to allow these browsers to display the page content. Therefore, the correct order to use the two is. First ob_flush, then flush. Of course, under other sapi, it is also possible not to call flush. However, in order to ensure the portability of your code, it is recommended to use them together.
There are some special considerations when using flush and ob_flush, which prevents the output buffer from being refreshed.
1. The correct order of flush and ob_flush, ob_flush first and then flush, as follows:
ob_flush();
flush();
If the operating system of the web server is a windows system, there will be no problem if the order is reversed or if ob_flush() is not used. But on Linux systems, the output buffer cannot be flushed.
2. Before using ob_flush(), make sure the previous content size is enough for 4069 characters .
The output_buffering of some web servers defaults to 4069 characters or larger, that is, the output content must reach 4069 characters before the server flushes the output buffer. In order to ensure that the flush is effective, it is best to have the following statement before the ob_flush() function:
print str_repeat(" ", 4096);
to ensure that the output_buffering value is reached.