ob caching mechanism

1. The buffer, i.e. buffer, ob is shorthand output_buffering

2.echo、print_r=>php output_buffering=>webServer buffer=>browser buffer=>browser display

Function from the echo, print_r to send a message to the client went through two buffers, the client has gone through a browser's cache.
In other words, when you echo output data, in fact, is to go through a layer of cache, only that this buffer is off by default, when we open, the output data, it will go a buffer, when the buffer after the data is automatically output full.


3 .. If turned in the program ob_start (), all outputs of the echo are saved to the cache ob, ob series function can be used to operate, and if not, by default, the program execution ends, the transmission data buffer will to the browser

The basic principle of ob: ob cache if open, the echo of the first data on the ob cache. If header information, directly on the cache. When the page execute in the end, it will ob cached data into the program cache, and then turn back to the browser

4. The
basic function of the ob:
1) to prevent re-use setcookie (), header () or session_start () after the browser has a function output, an error caused by a transmission header file. In fact, such use less is better, to develop good coding practices.
2) to capture the output of some functions can not be obtained, such as phpinfo () outputs a lot of HTML, but we can not for example use a variable $ info = phpinfo (); to capture this time ob it loose.
3) the content of the output processing, for example, gzip compression, for example, simplified conversion, for example, replaced some string.
4) generate static document, in fact, it is to capture the output of the whole page, and then saved as files. Often generate HTML, or full page cache used.

 

ob_start (): Open the output buffer control
Return Value: returns TRUE on success, failure or FALSE.

ob_get_contents (): returns the contents of the output buffer
Return Value: content output buffer, the output buffer is not valid or if the return FALSE

ob_clean (): Clear (erase) the output buffer contents. No return value

ob_end_clean: delete the contents of the internal buffer, and turn off the internal buffer
Return value: returns TRUE on success or FALSE on failure

ob_flush (): flushing out (sent out) the contents of the output buffer. No return value

ob_end_flush: transmitting the content of the internal buffer to the browser, and closes the output buffer.
Return Value: Returns TRUE on success or FALSE on failure

Guess you like

Origin www.cnblogs.com/pl0418/p/11502512.html