How to solve the problem of php flush failure under nginx

王林
Release: 2020-11-11 15:43:43
forward
2010 people have browsed it

How to solve the problem of php flush failure under nginx

Problem

When I was debugging PHP line-by-line output, I found that both ob_flush and flush failed. I can basically judge the settings of php.ini through phpinfo. normal.

(Learning video sharing: php video tutorial)

Solution

Looking at Nginx again, I found that there are the following settings in Nginx:

fastcgi_buffer_size 128k;
fastcgi_buffers 8 128k;
Copy after login

The problem is basically found. Nginx will buffer the information output by PHP. When it reaches 128k, the buffer data will be sent to the client. Then we first need to reduce the buffer size, such as:

fastcgi_buffer_size 4k;
fastcgi_buffers 8 4k;
Copy after login

And, gzip

gzip off;
Copy after login

Then, in php, before ob_flush and flush, output a piece of content reaching 4k, for example:

echo str_repeat(‘ ‘, 1024*4);
Copy after login

At this point, PHP The required content can be output line by line through ob_flush and flush normally.

Related recommendations: nginx tutorial

The above is the detailed content of How to solve the problem of php flush failure under nginx. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:gxlcms.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template