Php ob_flush () and flush () Usage
Note: The ob_flush () and flush () functions must be used together. The order is first ob_flush () and then flush (). Their role is to refresh the buffer zone.
Here we will explain when to use the refresh buffer and why to refresh the buffer.
I. When should I refresh the buffer?
When file_get_contents () and file_put_contens () functions are used in the program, ob_flush () is used to execute similar "read/write" functions in the program or perform output operations to the browser () and flush () to refresh the buffer.
Ii. Why refresh the buffer?
Use file_get_contents () and file_put_content () as examples.
The file_get_contents () and file_put_conents () functions read data and write data respectively. Data is first read to the memory and then written to the file, because the read speed is faster than the write speed, when your data is read, it does not mean that the data is also written, at this time, the read content will be temporarily stored in the buffer (memory). Here, we need to emphasize that Data Reading and writing are two very fast actions.
It also uses an explanation (when a program executes an output operation to a browser). Before sending the result to a browser, some web server programs, especially the web server programs under Win32, the Script output will still be cached until the program ends. If you do not want the program to be output to the handler after execution, you can also use ob_flush () and flush () to refresh the cache.
In fact, flush () has another purpose, that is, to output some results to the browser before a loop ends, this effect is similar to ajax's asynchronous transmission effect.
Measure the test taker's understanding about the differences between ob_flush and flush.
Ob_flush/flush descriptions in the manual are used to refresh the output buffer and must be used together, which may lead to many confusion...
In fact, they have different operation objects. In some cases, flush does nothing at all ..
Ob _ * series functions are used to operate the output buffer of PHP itself.
Therefore, ob_flush is used to refresh the PHP buffer.
But flush, strictly speaking, this is only useful when PHP is installed as an apache Module (handler or filter. it is used to refresh the buffer zone of the WebServer (which can be considered to be specific to apache.
In the sapi of apache module, flush indirectly calls apache api: ap_rflush to refresh apache output buffer by calling the flush member function pointer of sapi_module, some other modules of apache may change the result of this action ..
Some Apache modules, such as mod_gzip, May output the cache by themselves, which will cause the results produced by the flush () function to be not immediately sent to the client browser.
Even the browser caches the received content before it is displayed. For example, the Netscape Browser caches content before it receives a line break or the beginning of an html Tag, and does not display the entire table until it receives the </table> tag.
In some versions of Microsoft Internet Explorer, the page is displayed only after 256 bytes are received. Therefore, some extra spaces must be sent for these browsers to display the page content, the correct order is. first ob_flush, then flush,
Of course, other sapis do not call flush, but we recommend that you use it to ensure the portability of your code.