3

since two days i'm trying to stop the buffer on my server, i disabled the output_buffering in php.ini i checked it was disabled with phpinfo().

Under xampp(Localhost) it works like a charm, same testing code(below), the code runs without waiting for everything to be finished, no buffer, a dream =)

On my server the output_buffering show me No value in phpinfo() so i think it's disabled, but still it's not workingn i need to wait until the loop finish his work, anyway to make this work like on my xampp config ? thanks !

testing code here :

for($i=1; $i<=5000; $i++){
    echo $i."<br>";

    flush();
    usleep(1000);
}

ps : i tested with php 5.6 & php7 on Debian and Ubuntu, my xampp is naturally running on windows(10)

  • if you want this kind of browser interaction you should use client side code –  Nov 22 '16 at 20:06
  • Possible duplicate of [How to flush output after each \`echo\` call?](http://stackoverflow.com/questions/3133209/how-to-flush-output-after-each-echo-call). Check out the second answer which appears to solve it by sending out a content-type header. – Jonathan Kuhn Nov 22 '16 at 20:24

2 Answers2

0

You need to use ob_flush() and flush()

What's the difference you may ask? That's a good question.

Community
  • 1
  • 1
Dellowar
  • 3,160
  • 1
  • 18
  • 37
0

Modern browsers don't display anything until the body of the response contains a certain amount of data (about 1024 bytes). The following may look a bit hacky - but like this it works as expected:

<?php
echo '<!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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