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;
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;
And, gzip
gzip off;
Then, in php, before ob_flush and flush, output a piece of content reaching 4k, for example:
echo str_repeat(‘ ‘, 1024*4);
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!