Solution to the invalid PHP flush function in Nginx

Source: Internet
Author: User
Tags flush

When debugging PHP line-by-line output, it is found that both ob_flush and flush are invalid. Through phpinfo, the php. ini settings are normal.

Check Nginx again and find that Nginx has the following settings:

Fastcgi_buffer_size 128 k;
Fastcgi_buffers 8 128 k;

The problem is basically found. Nginx will buffer the PHP output information and send the data in the buffer zone to the client only when it reaches K. Then we need to reduce the buffer zone first, for example:

Fastcgi_buffer_size 4 k;
Fastcgi_buffers 8 4 k;

In addition, gzip must be disabled.

Gzip off;

Then, in php, before ob_flush and flush, output a piece of content that reaches 4 K. For example:

Echo str_repeat ('', 1024*4 );

By now, PHP can output the required content through ob_flush and flush row by row.


Note: IE must receive 256 bytes before Display starts.

Therefore, we need to add echo str_pad ("", 256 );

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.