Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
BTW I noticed my php.ini, while the default value is "off" there was still an uncommented "output_buffering = 4096" in there. Anyway, great question! –  PJ Brunet Nov 12 '13 at 17:53
1  
Apparently it's possible to do this, without disabling gzip, as of Nginx 1.5.6 with the new "fastcgi_buffering" directive twitter.com/mdounin/status/400259731308032000 –  PJ Brunet Nov 12 '13 at 17:56
add comment

3 Answers

up vote 1 down vote accepted

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)

share|improve this answer
    
There’s really no way to completely disable the buffer? My reading of the nginx wiki/docs seems to suggest that the disk cache is the easiest thing to shut off, but the memory cache is still in play, despite various attempts to shut it down too. But maybe I’m reading it wrong… –  Abraham Vegh Mar 18 '13 at 10:25
1  
There is for pretty much everything but fastcgi. uwsgi has wiki.nginx.org/HttpUwsgiModule#uwsgi_buffering proxy has nginx.org/en/docs/http/…. but the same does not exist for fastcgi. –  Martin Fjordvald Mar 18 '13 at 15:06
add comment

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.

share|improve this answer
    
If anyone gets progressive gzip working, please email me pj@pjbrunet.com or just reply here. But I can affirm this works (without gzip) wow! Now my css and js files load immediately. According to this phpied.com/progressive-rendering-via-multiple-flushes progressive gzip rendering is possible. But with Apache and not NginX? It's a fascinating link but lacks in-depth implementation details :-/ –  PJ Brunet Nov 12 '13 at 13:37
    
Also I wonder if there's a "no-gzip" encoding option that could improve this answer? –  PJ Brunet Nov 12 '13 at 17:55
add comment

It IS possible, look at this answer.

I tried it myself and it works.


Upgrade your nginx server {} config:

fastcgi_keep_conn on; # < solution

proxy_buffering off;
gzip off;
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.