About caching functions in PHP
Ob_start () and Ob_end_flush ().
PHP output mechanism: output---cache--output to the browser.
Ob_start (callback function) opens the output buffer, and all output information is no longer sent to the browser, but is processed at the callback function.
Ob_end_flush (); Output all the contents of the buffer and close the buffer.
The effect of OB output buffering:
1. Prevent errors caused by using Setcookie, header, session_start () function improperly (after output).
2. Capture some non-accessible output, such as the output of phpinfo (), the server can use the OB function to obtain the server information saved as a file without output, so that can be friendly or covert access to the server information.
3. Process the content of the output, such as faster transfer: After capturing the content, compress the content using gzip, and then use unzip at the receiving point, which speeds up the file transfer. or the content of other processing, such as Chinese and English processing, encoding processing.
4. Generate static file, static template technology: Can let the output of PHP write to an HTML file, if there is no dynamic access, directly let the user see that static page, if there is input access, then call PHP file, re-write HTML page, This has a great effect on the performance improvement of a website with large traffic.
Description of the correlation function:
Ob_start () Open buffer
Ob_flush () Refreshes the contents of the buffer, the output
Ob_get_contents () returns the contents of the buffer
Ob_get_length () returns the length of the buffer
Ob_end_flush () sends buffer contents to the browser and closes the buffer
Ob_end_clean () Delete buffer contents (not output), and close buffer
Ob_implicit_flush () turns absolute refresh on or off. When an absolute refresh is turned on, each script output is sent directly to the browser without the need to call the flush () function again.
PHP Learning Notes (eight)