Differences between flush (), ob_flush (), and ob_end_flush () in php. for details, see the differences among flush (), ob_flush (), and ob_end_flush:
First, let's talk about the buffer, which is a memory address space of 4096 (1 kb) [in php. output_buffering configuration is found in the ini configuration file. php has the php output_buffering mechanism. When php code is executed, the content is not output immediately, instead, the echo/print content is output to the buffer. when the buffer is full, the data is handed over to the system kernel and sent to the browser for display. when the php output_buffering mechanism is enabled (enabled by default, you can enable it through the ob_start () function. only when the data in the php buffer reaches the set value will the data in the buffer be sent to the browser.
However, the browser also has a cache. some versions of the browser output content only when the data reaches 256 bytes. flush () can send the content waiting for output to the client immediately, while ob_flush () it is output only when the buffer is full.
Here is a simple example for verification:
The code is as follows:
// Prevents browser caching
Echo str_repeat ("", 1024 );
For ($ I = 0; $ I <5; $ I ++ ){
Echo $ I;
Sleep (1 );
Flush (); // A number is output every 1 s. If ob_flush () is used, it will wait for 5s to output together.
}
?>