How to empty php buffer during execution?

3

I want something to print on the screen at runtime, not just when the script is finished, I tried:

<?php

ob_start();

for($i = 0; $i < 5; $i++){

   echo $i . '<br>';
   ob_flush();
   flush();

   sleep(3);
}

but did not work, everything is printed at once at the end of the run.

    
asked by anonymous 01.03.2017 / 19:39

1 answer

4

According to my tests, this works:

@ini_set("output_buffering", 0);  // off 
@ini_set("zlib.output_compression", 0);  // off
@ini_set("implicit_flush", 1);  // on   

header('Content-Type: text/plain');

ob_implicit_flush(true);

for ($i=0; $i<10; $i++) {

    echo $i;

    echo str_repeat(' ',1024*64);

    sleep(1);
}

I took this response from SOEN

    
01.03.2017 / 20:00