Nginx – How to enable PHP’s flush() with nginx+PHP-FPM

nginxPHPphp-fpm

I’m using nginx with PHP-FPM (APC is installed).

I need PHP’s flush() to work. Is this possible?

Things I’ve tried so far:

  • Disabling all output buffering in php.ini, as well as output compression.
  • Disabling gzip in nginx’s configuration.
  • Setting nginx’s fastcgi_* buffering settings and fastcgi_max_temp_file_size to zero.

I’m sure I must be missing something, since I’ve run across many posts here and elsewhere where people claimed they’ve got it working, but I’m having no luck, it would seem.

Best Answer

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