# SOS! Why Nginx DID NOT flush buffer to client?

**URL:** <https://www.ruby-forum.com/t/sos-why-nginx-did-not-flush-buffer-to-client/183160>\
**Category:** NGINX\
**Created:** [February 9, 2010, 9:29am UTC](https://www.ruby-forum.com/t/sos-why-nginx-did-not-flush-buffer-to-client/183160 "2010-02-09T09:29:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![21andy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/2/aca169/32.png) [@21andy](https://www.ruby-forum.com/u/21andy)\
**Post date:** [February 9, 2010, 9:29am UTC](https://www.ruby-forum.com/t/sos-why-nginx-did-not-flush-buffer-to-client/183160/1 "2010-02-09T09:29:45Z")

</div>

I want to the php file output 1 line per second.

see my code first:

\<?php ob\_implicit\_flush(true); for ($i = 0; $i \< 5; $i++) { echo "test $i"; sleep(1); } ?\>

OR

\<?php ob\_end\_clean(); for ($i = 0; $i \< 5; $i++) { echo "test $i"; flush(); sleep(1); } ?\>

Both not work, they output all the content after 5 seconds. NOT 1 second  
1 line.

I tried to change nginx.conf  
gzip on; AND gzip off;  
and it still NOT 1 second 1 line.

and I also tried to change php.ini  
output\_buffering = 4096  
AND  
output\_buffering = 0  
and it still NOT 1 second 1 line.

HOW CAN I FIX IT ?  
SOS!!!

Posted at Nginx Forum:

> **[SOS! Why Nginx DID NOT flush buffer to client?](https://forum.nginx.org/read.php?2,52531,52531#msg-52531)**
>
> I want to the php file output 1 line per second. see my code first: \<?php ob\_implicit\_flush(true); for ($i = 0; $i \< 5; $i++) { echo "test $i\<br /\>"; sleep(1); } ?\>

---

<div class="post-metadata">

**Author:** ![21andy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/2/aca169/32.png) [@21andy](https://www.ruby-forum.com/u/21andy)\
**Post date:** [February 9, 2010, 5:07pm UTC](https://www.ruby-forum.com/t/sos-why-nginx-did-not-flush-buffer-to-client/183160/2 "2010-02-09T17:07:31Z")

</div>

On 02/09/2010 10:29 AM, 21andy wrote:

> ?\>  
> ?\>  
> output\_buffering = 0  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

Hi,

Try ob\_end\_flush() instead of ob\_end\_clean().

/gh

---

<div class="post-metadata">

**Author:** ![21andy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/2/aca169/32.png) [@21andy](https://www.ruby-forum.com/u/21andy)\
**Post date:** [February 11, 2010, 10:18am UTC](https://www.ruby-forum.com/t/sos-why-nginx-did-not-flush-buffer-to-client/183160/3 "2010-02-11T10:18:47Z")

</div>

21andy wrote:

> I want to the php file output 1 line per second.

I know it’s not an answer to your question, but you should re-evaluate  
your application architecture. If you need progress report on lengthy  
operations you can use separate batch processes, messaging queues,  
databases, Ajax, and all sorts of tools.

The reason nginx buffers all output is because, most of the times,  
generating the response is a much faster operation than transferring it  
to the client. Therefore, by buffering it, nginx frees the backend  
worker (the php child process) sooner and the system is able to serve  
more requests per unit of time, for a given amount of ram. Which is one  
of the main aims of server optimization.

Hope this explains the logic behind it.

Tobia

---

<div class="post-metadata">

**Author:** ![21andy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/2/aca169/32.png) [@21andy](https://www.ruby-forum.com/u/21andy)\
**Post date:** [February 15, 2010, 11:40am UTC](https://www.ruby-forum.com/t/sos-why-nginx-did-not-flush-buffer-to-client/183160/4 "2010-02-15T11:40:11Z")

</div>

Hi,

> I want to the php file output 1 line per second.

take a look at the fastcgi buffer settings:

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

Cheers,  
Daniel

You wrote:

> OR  
> Both not work, they output all the content after 5 seconds. NOT 1 second 1 line.
> 
> HOW CAN I FIX IT ?  
> SOS!!!

–  
[http://daniel.hahler.de/](http://daniel.hahler.de/)

---

<div class="post-metadata">

**Author:** ![21andy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/2/aca169/32.png) [@21andy](https://www.ruby-forum.com/u/21andy)\
**Post date:** [February 9, 2010, 5:53pm UTC](https://www.ruby-forum.com/t/sos-why-nginx-did-not-flush-buffer-to-client/183160/5 "2010-02-09T17:53:46Z")

</div>

It doesn’t matter as I believe NginX buffers fastcgi responses and  
then sends to the client once the request is completed.

V/r  
Rob

Sent from my iPhone

On Feb 9, 2010, at 10:06 AM, Georgi H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![21andy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/2/aca169/32.png) [@21andy](https://www.ruby-forum.com/u/21andy)\
**Post date:** [February 15, 2010, 6:35pm UTC](https://www.ruby-forum.com/t/sos-why-nginx-did-not-flush-buffer-to-client/183160/6 "2010-02-15T18:35:11Z")

</div>

On Feb 15, 2010, at 4:39 AM, Daniel H. wrote:

> Hi,
> 
> > I want to the php file output 1 line per second.
> 
> take a look at the fastcgi buffer settings:  
> [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/NginxHttpFcgiModule#fastcgi_buffers)

That won’t help since if the buffer’s are too small then NginX will just  
buffer it to a tmp file on the disk until the request is completed from  
the fastcgi process.

V/r,  
Rob

---

<div class="post-metadata">

**Author:** ![21andy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/2/aca169/32.png) [@21andy](https://www.ruby-forum.com/u/21andy)\
**Post date:** [May 16, 2012, 8:58am UTC](https://www.ruby-forum.com/t/sos-why-nginx-did-not-flush-buffer-to-client/183160/7 "2012-05-16T08:58:23Z")

</div>

Syntax: proxy\_buffering on | off  
Default: on  
Context: http  
server  
location  
Reference: proxy\_buffering

Posted at Nginx Forum:

> **[Re: SOS! Why Nginx DID NOT flush buffer to client?](https://forum.nginx.org/read.php?2,52531,226482)**
>
> I want to the php file output 1 line per second. see my code first: \<?php ob\_implicit\_flush(true); for ($i = 0; $i \< 5; $i++) { echo "test $i\<br /\>"; sleep(1); } ?\>
