The buffer for PHP is this:
The output string = = PHP Buffer = Wait for the output of the buffer of the Web server = + TCP buffer = client. The process is actually quite complex.
Approximate working mechanism:
BOOL Ob_start ([callback $output _callback [, int $chunk _size [, bool $erase ] ]]) This function I want to emphasize the second parameter:
If the optional parameter chunk_size is assigned, the buffer will be brushed after any output operation that causes the buffer length to be equal to or greater than chunk_size . The default value of 0 means that after the script finishes, the buffer is brushed, and the rest of the special values can be set from 1 to 4096 chunk_size .
This parameter is 0 by default.
Also, buffers can be nested. This is crucial. For example, if you call two Ob_start, you will create a two buffer. The second time the buffer is created, the buffer that is created for the first time is written, and the buffer created by Ob_start is always written to output_buffering =on when the system automatically creates the buffer.
Let's take a look: Ob_end_flush, the function is to close the last open buffer and feed the contents into the next buffer. If the next buffer does not, it enters the state of waiting for the output.
Flush is the content that refreshes waits for output to go to the browser. The premise is that the content is waiting for the output state, not in the buffer, and it does not affect the contents of the buffer.
Look at your code again:
If output_buffering = ON, then the system creates a buffer by default, which is typically 2K. The contents of the Ob_end_flush will enter this buffer without going into the output wait. So the call to flush doesn't have a single effect. Until the end of the script, PHP sends out all the content.
If the contents of output_buffering = Off Ob_end_flush into the output wait state, this time flush, the content can be output.
Of course, this is just the case analysis at the end of PHP.
There are other factors that affect the final output:
Individual Web server programs, especially Web server programs under Win32, will still cache the output of the script until the end of the program, before sending the results to the browser.
Some Apache modules, such as Mod_gzip, may make their own output caches, which will result in the flush () function producing results that are not immediately sent to the client browser.
Even the browser will cache the received content before it is displayed. For example, the Netscape browser caches content before it accepts the start of a newline or HTML tag, and does not display the entire table until the </table> tag is accepted.
Some versions of Microsoft Internet Explorer do not start to display the page until 256 bytes are accepted, so you must send some extra spaces to let these browsers display the page content.
The mechanism of PHP buffer