How to disable output buffering with PHP and nginx

Francis Daly francis at
Mon Oct 7 21:35:07 UTC 2013

On Mon, Oct 07, 2013 at 03:22:15PM -0400, Ben Johnson wrote:
> On 9/16/2013 1:19 PM, Ben Johnson wrote:

Hi there,

> > For whatever reason, nginx *always* buffers the output, even when I set

> > Is it possible to disable PHP output buffering completely in nginx?

Have you shown that the initial problem is on the nginx side?

I suspect it will be more interesting to people on this list if you
have a simple test case which demonstrates that it is nginx which is
buffering when you don't want it to.

Use a php script like this:

echo "The first bit";
echo "The second bit";

Run the fastcgi server like this:

  env -i php-cgi -d cgi.fix_pathinfo=0 -q -b 9009

Use an nginx config which includes something like this:

  location = /php {
    fastcgi_param SCRIPT_FILENAME /usr/local/nginx/test.php;

Then do something like

  tcpdump -nn -i any -A -s 0 port 9009

while also doing a

  curl -i

and look at the network traffic from the fastcgi server.

If you don't see a five-second gap between the two different response
packets, it is being buffered before it gets to nginx.

Now make whichever please-don't-buffer changes seem useful in the php code
and in the fastcgi server configuration. When you can see non-buffered
output getting to nginx, then you know the non-nginx side is doing what
you want. So now you can start testing nginx configuration changes;
and you can share the exact non-nginx configuration you use, so that
someone else can copy-paste it and see the same problem that you see.

(Change to be whatever remote server runs your fastcgi
server, if that makes it easier to run tcpdump.)

Good luck with it,

Francis Daly        francis at

More information about the nginx mailing list