I copied a piece of buffer code from the official PHP manual, but the execution result is wrong!

Source: Internet
Author: User
The address for copying the code is: fr2.php. netmanualhfunction. ob-flush.php #109314 my code is as follows, after execution is not displayed line by line, but waited for a long time, came out together: {code ...} OS: Macosx10.9webservice: nginx1.4p... the address where I copied the code is: http://fr2.php.net/manual/zh/function.ob-flush.php#109314

My code is as follows. After execution, it is not displayed line by line, but after a long time, it appears together:

header('Content-type:text/html; charset=utf-8');if (ob_get_level() == 0) ob_start();for ($i = 0; $i<10; $i++){    echo "
Line to show."; echo str_pad(' ',4096)."\n"; ob_flush(); flush(); sleep(2);}echo "Done.";ob_end_flush();

OS: Mac osx 10.9
Webservice: nginx 1.4
Php 5.6

Reply content:

The address where I copied the code is: http://fr2.php.net/manual/zh/function.ob-flush.php#109314

My code is as follows. After execution, it is not displayed line by line, but after a long time, it appears together:

header('Content-type:text/html; charset=utf-8');if (ob_get_level() == 0) ob_start();for ($i = 0; $i<10; $i++){    echo "
Line to show."; echo str_pad(' ',4096)."\n"; ob_flush(); flush(); sleep(2);}echo "Done.";ob_end_flush();

OS: Mac osx 10.9
Webservice: nginx 1.4
Php 5.6

There is no problem with running.
Line to show.
Line to show.
Line to show.
Line to show.
Line to show.
Line to show.
Line to show.
Line to show.
Line to show.
Line to show. Done.

PHP version too high

If the value of the ob_get_level () function is 0, the output buffer is not enabled if the value is 0. My ob_get_level () returns 1.

Note:flushAndob_flushDifferences:
ob_flushThe operation isphpIts ownbuffer
flushThe operation isapacheOfflushThat is to say, this pairnginxIs ineffective

In nginx, try the following settings:

Fastcgi_max_temp_file_size 0 # disable the disk buffer fastcgi_buffers 1 1 1 k # Set the buffer to a small value

Edit php. ini, set output_buffering = 0 to disable the buffering mechanism, and restart the server.

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.