Ob_start () solution

Source: Internet
Author: User
Ob_start () tutorial & lt ;? Phpob_start (); --------------------------- 1for ($ s0; $ s & lt; 300; $ s ++) {echo;} ob_end_clean (); then 2for ($ var0; $ var & lt ob_start () tutorial
Ob_start (); // ------------------------------- 1

// For ($ s = 0; $ s <= 300; $ s ++) {echo '';}

// Ob_end_clean (); // -------------------------------------- 2

For ($ var = 0; $ var <= 10; $ var ++ ){
Echo $ var;
Print str_repeat ("", 4096 );
Ob_flush (); // -------------------------- 3
Flush (); // -------------------------- 4
Sleep (1); // -------------------------- 5
}
?>
An example of a buffer test is displayed. when the ob_start () function is used, [3] releases the buffer content and [4] sends the content no longer in the buffer to the page, [5] The message is sent once per second, but why does it wait 10 seconds before sending all the content.

I checked a lot of articles and many said that I used the method at [2] to comment out [1] [3], but in this way I disabled the buffer zone,

The Php statement on the Internet is called an internal buffer or a buffer. I don't know if it is a thing.
Is the output_buffering buffer in the Php. ini file enabled by ob_start?

------ Solution --------------------
Ob_flush is not very useful. please refer to the official documentation.
Http://il.php.net/manual/en/function.ob-flush.php

Some problems with ob_flush () and flush () cocould be resolved by defining content type header:
Header ('content-type: text/html; charset = utf-8 ');

So working code looks like this:
Header ('content-type: text/html; charset = utf-8 ');
Echo 'In in...
';
For ($ I = 0; $ I <10; $ I ++)
{
Echo $ I .'
';
Flush ();
Ob_flush ();
Sleep (1 );
}
Echo 'end...
';
?>

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.