This article will give you a summary of the usage and differences between flush (), ob_flush (), and ob_end_flush () in php. For more information, see the reference.
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, browsers also have caches. Some versions of browser output content only when the data reaches 256 bytes,
Ob_start () function: Open the output buffer.
Function Format void ob_start (void)
Note: When the buffer zone is activated, all non-file header information from the PHP program is not sent, but stored in the internal buffer zone. To output the buffer content, you can use ob_end_flush () or flush () to output the buffer content.
Flush: refresh the buffer content and output it.
Function Format: flush ()
Note: This function is frequently used and highly efficient.
Ob_get_contents: returns the content of the internal buffer.
Function Format: string ob_get_contents (void)
Note: This function returns the content in the Current Buffer. If the output buffer is not activated, FALSE is returned.
Ob_get_length: returns the length of the internal buffer.
Function Format: int ob_get_length (void)
Note: This function returns the length of the Current Buffer. It is the same as ob_get_contents. If the output buffer is not activated, FALSE is returned.
Ob_end_clean: Delete the content of the internal buffer and disable the internal buffer.
Function Format: void ob_end_clean (void)
Note: This function will not output the content of the internal buffer but delete it.
Ob_end_flush: sends the content of the internal buffer to the browser and closes the output buffer.
Function Format: void ob_end_flush (void)
Description: This function sends the content of the output buffer (if any)
Ob_implicit_flush: Enables or disables absolute refresh.
Function Format: void ob_implicit_flush ([int flag])
Note: the buffer zone is disabled by default. After absolute output is enabled, the output of each script is directly sent to the browser, and you do not need to call flush ()
Flush () can immediately send the content waiting for output to the client, while ob_flush () can only output the content when the buffer is full. You can verify it using the following simple php instance:
Instance
The Code is as follows: |
Copy code |
<? Php // This 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, but the use of ob_flush () will wait for 5s to output together. } ?> |