The differences of flush of ob_flush of ob_end_flush of in php are introduced
- 2020-05-30 19:40:50
- OfStack
flush(), ob_flush(), ob_end_flush()
buffer under the first, say, it is a memory address space, 4096 (1 kb) [in php. ini configuration file found output_buffering match buy 】, there php php output_buffering mechanism, php code at the time of execution, will not immediately content output, but want the output to buffer echo/print content, buffer when it is full of the data to the system kernel to tcp to the browser to display, When the php php output_buffering mechanism is enabled (by default, it can be enabled through the ob_start() function), the data in php buffer will only be sent to the browser if the data in buffer reaches the set value.
But 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() will output only when buffer is full.
Here is a simple example for you to verify:
<?php
// Prevents the browser from caching
echo str_repeat(" ",1024);
for($i=0;$i<5;$i++){
echo $i;
sleep(1);
flush();// every 1s The output 1 Number, if used ob_flush() Will be waiting for 5s1 The output
}
?>