Forum: NGINX php flush() are not effective.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ken Chen (Guest)
on 2009-04-29 19:27
(Received via mailing list)
Hi all,

I am trying to flush content before the end of PHP script. With below
script, it works under lighttpd, but not work after changing to nginx.

<?php

ob_flush();
echo "The first line<br />";
flush();
sleep(2);

for ($i=10; $i>0; $i--)
{
    echo $i . "<br />";
#    echo str_repeat(" ",8192);
    ob_flush();
    flush();
    sleep(1);
}
ob_end_flush();
?>
Olivier B. (Guest)
on 2009-04-29 19:54
(Received via mailing list)
Hi,

you probably have to reduce the NginX buffers :
http://wiki.nginx.org/NginxHttpFcgiModule#fastcgi_buffers

Olivier

Ken Chen a écrit :
Shri @ DevLib.Org (Guest)
on 2009-04-29 20:05
(Received via mailing list)
I've noticed this too. Can you retry after turning gzip off? Worked in
my case.

We have some scripts which run for 20-30 mins, rebuilding some large
databases and they need to be run isolated from the main webserver which
has gzip on.

Regards,
Shri

  ----- Original Message -----
  From: Ken Chen
  To: removed_email_address@domain.invalid
  Sent: Wednesday, April 29, 2009 11:20 PM
  Subject: php flush() are not effective.


  Hi all,

  I am trying to flush content before the end of PHP script. With below
script, it works under lighttpd, but not work after changing to nginx.

  <?php

  ob_flush();
  echo "The first line<br />";
  flush();
  sleep(2);

  for ($i=10; $i>0; $i--)
  {
      echo $i . "<br />";
  #    echo str_repeat(" ",8192);
      ob_flush();
      flush();
      sleep(1);
  }
  ob_end_flush();
  ?>
Ken Chen (Guest)
on 2009-04-29 22:15
(Received via mailing list)
hi Shri,

Thanks a lot! It works.

I change the nginx configuration to:

fastcgi_buffer_size 4k;
gzip  off;

And PHP script:

<?php

ob_flush();
echo The first line<br />";
flush();
sleep(2);

for ($i=10; $i>0; $i--)
{
    echo $i . "<br />";
    echo str_repeat(" ",4096);
    ob_flush();
    flush();
    sleep(1);
}
ob_end_flush();
?>

But how do you implement them to the productive server?

Set 'zlib.output_compression = On' in php.ini, and only compress static
content in nginx.conf ?


Regards,
Ken

2009/4/29 Shri @ DevLib.Org <removed_email_address@domain.invalid>
Shri @ DevLib.Org (Guest)
on 2009-04-30 05:35
(Received via mailing list)
Ken - The PHP directive / PHP.INI setting is of no use, as the webserver
is compressing and buffering the output.

You might want to consider turning the gzip on and off depending on the
location. According to http://wiki.nginx.org/NginxHttpGzipModule gzip on
| off is supported down to a location level.

Did you need to change the fastcgi_buffer_size variable? Best to change
one variable at a time and figure what causes / fixes the problem (and
change back to see if the old symptoms reappear).

Regards,
Shri

  ----- Original Message -----
  From: Ken Chen
  To: removed_email_address@domain.invalid
  Sent: Thursday, April 30, 2009 2:03 AM
  Subject: Re: php flush() are not effective.


  hi Shri,

  Thanks a lot! It works.

  I change the nginx configuration to:

  fastcgi_buffer_size 4k;
  gzip  off;

  And PHP script:

  <?php

  ob_flush();
  echo The first line<br />";
  flush();
  sleep(2);

  for ($i=10; $i>0; $i--)
  {
      echo $i . "<br />";
      echo str_repeat(" ",4096);
      ob_flush();
      flush();
      sleep(1);
  }
  ob_end_flush();
  ?>

  But how do you implement them to the productive server?

  Set 'zlib.output_compression = On' in php.ini, and only compress
static content in nginx.conf ?


  Regards,
  Ken


  2009/4/29 Shri @ DevLib.Org <removed_email_address@domain.invalid>

    I've noticed this too. Can you retry after turning gzip off? Worked
in my case.

    We have some scripts which run for 20-30 mins, rebuilding some large
databases and they need to be run isolated from the main webserver which
has gzip on.

    Regards,
    Shri

      ----- Original Message -----
      From: Ken Chen
      To: removed_email_address@domain.invalid
      Sent: Wednesday, April 29, 2009 11:20 PM
      Subject: php flush() are not effective.


      Hi all,

      I am trying to flush content before the end of PHP script. With
below script, it works under lighttpd, but not work after changing to
nginx.

      <?php

      ob_flush();
      echo "The first line<br />";
      flush();
      sleep(2);

      for ($i=10; $i>0; $i--)
      {
          echo $i . "<br />";
      #    echo str_repeat(" ",8192);
          ob_flush();
          flush();
          sleep(1);
      }
      ob_end_flush();
      ?>
This topic is locked and can not be replied to.