2
votes

It seems that despite everything i've done trying to get it to work, It just doesnt work.

Here's what all I did :

  1. output_buffering = 4096
  2. zlib.output_compression = Off
  3. Tried using ob_implicit_flush();
  4. Tried using ob_flush();
  5. Reduced the buffer size in the ini setting output_buffering to 1

Following is the code that i'm trying to get to work (basically output a line every 1 second) but i'm getting the entire output after 15 seconds.

With ob_implicit_flush() :

<?php
ob_implicit_flush();

for($i=0;$i<=15;$i++)
{
    print($i."<BR />");
    sleep(1);
}

with using ob_start() and ob_flush() methods :

<?php
ob_start();
for($i=0;$i<=15;$i++)
{
    print($i."<BR />");
    ob_flush();
}

Is there any other PHP setting that I am missing ? Please help.

EDIT : Using the example by the OP in this SO question, it works : PHP buffer why \r\n

I see that I had to do a str_repeat() to generate a string to overflow the buffer. Why is nothing of this mentioned in the php manual ? Is this really the procedure ?

2
This code looks incomplete. I cannot see the calls to the ob_* set of functions in the context of the samples.Treffynnon
sorry about that, i've updated it now.YD8877

2 Answers

1
votes

PHP returns one response to a request. If you have sleep() calls in that code then the whole response will wait for those calls. PHP doesn't pass a response back to the browser in chunks even if you put a one second sleep in between prints.

If you are using PHP as an interactive console then this could should work and behave as you are anticipating.

0
votes

Read http://www.php.net/flush description, it can help you to understand what happens.