Differences between flush (), ob_flush (), and ob_end_flush () in php

Source: Internet
Author: User
Differences between flush (), ob_flush (), and ob_end_flush () in php. for details, see the differences among flush (), ob_flush (), and ob_end_flush:

First, let's talk about the 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, the browser also has a cache. some versions of the browser output content only when the data reaches 256 bytes. flush () can send the content waiting for output to the client immediately, while ob_flush () it is output only when the buffer is full.

Here is a simple example for verification:

The code is as follows:


// 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. If ob_flush () is used, it will wait for 5s to output together.
}
?>

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.