I have php 5.5 (fpm) and nginx 1.10 installed (gzip configured to 1). Running on ubuntu.

When I am "echoing" a large output (over 2 mb), it stops abruptly at around 520 kb.

But same program when I run on php-cli, it has no problem "echoing" the whole thing onto the terminal.

Also downloading mysql dumps through adminer gets stopped in the half way. I mean incomplete files get downloaded (if the correct total output is bigger in couple of MBs).

How to fix this?

There is nothing wrong with my program. Even a simple long enough for loop spurting out echo "hello world" gets stopped at specific byte limit.

I am not sure if this issue is caused from nginx side or php side.

  • If it is due to nginx, you can find out if you enable debugging log. Ref: nginx.org/en/docs/debugging_log.html . If you can't decode the debug log, please post it here for one such failed request. – Pothi Kalimuthu Oct 20 '16 at 11:54
  • Unclear from your description: Are you echoing the large output into a browser? Are you downloading the mysql dumps through a browser? If the answer to both of these is "yes", then look for something between the service and your browser, like a corporate proxy that limits downloads larger than (probably) 512 KB (or half a MB). – Larry Silverman Oct 25 '16 at 18:00
  • 1
    There is no proxy. I am echoing directly into a browser. imagine a for loop and echo in it for very long number of times.. and php max script execution time is set to 0 (know thats not the bottleneck). – hakacadera Oct 25 '16 at 18:31
  • Try calling flush() and optionally ob_flush() (if ob_start was previously used) after every output. The way it is now, the output could bloat the output buffers. – Zdenek Jun 18 '18 at 19:41

Try disabling buffering:

fastcgi_buffering off;

It's on by default.

This will give you a bit more control from within PHP, but be aware that flushing operations that didn't block previously may now block. It will also overcome any buffering issues Nginx may be encountering--I'd put my money on that being the issue. Nginx's buffers are efficient but fickle.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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