How to use Ob_flush () and flush () for PHP

Source: Internet
Author: User
Note: Ob_flush () and flush () These two functions are generally used together, in order to Ob_flush () first, then flush (), and their function is to flush the buffer. Here's a specific next time to use the flush buffer and why to flush the buffer.

Note: the Ob_flush () and flush () functions are generally used together, in order to Ob_flush () first, then flush (), and their function is to flush the buffer. Here's a specific next time to use the flush buffer and why to flush the buffer.

First, when to flush buffers when using the file_get_contents () and File_put_contens () functions in a program, or to perform a similar "read and write" in a program function or perform an output operation to the browser, Ob_flush () and flush () are used to flush the buffer.

Second, why to flush the buffer use file_get_contents () and File_put_content () as an example to explain. The

file_get_contents () and file_put_conents () functions perform both read and write data operations, where the data is read into memory and then written to the file, because the read speed is faster than the write, So when your data is read, it does not mean that the data is written, this time the content will be temporarily put into the buffer (memory), where it needs to be emphasized, in fact, the data read and write is two very fast action oh.

Also uses an explanation (when the program performs output operations to the browser), and individual Web server programs, especially Web server programs under Win32, still cache the output of the script until the end of the program, before sending the results to the browser. You can also use Ob_flush () and flush () to flush the cache if you do not want the program to complete before you print it out.

In fact, flush () also has a purpose, that is, before the end of the program before the output, that is, a loop is not finished to output some of the results to the browser, this effect is similar to Ajax asynchronous transmission effect.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.