2

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 ?

Community
  • 1
  • 1
YD8877
  • 10,401
  • 20
  • 64
  • 92

2 Answers2

1

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.

Treffynnon
  • 21,365
  • 6
  • 65
  • 98
0

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

Electronick
  • 1,122
  • 8
  • 15