How do I enable PHP’s flush() with nginx+PHP-FPM?

Solution 1:

Sadly it's not possible with nginx. The nginx implementation of fastcgi requires a buffer to be in place, even if you set the buffering directive to 0 it will just cause it to buffer to disk instead of memory.

You'll have to figure out some alternative system such as a queue where you can poll for the status. (think ala gearman for instance)

Edit: This is since possible: http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_buffering

Solution 2:

I wanted the same thing, and it turns out it is possible. All you need is this before anything is echo'ed:

header('Content-Encoding: none;');

Then to flush you do the flush as normal:

ob_end_flush();
flush();

Nginx seems to pick up on the encoding having been turned off and doesn't gzip.