PHP show results while running

apache, debian, flush, linux, php

Solution

I used this way from this answer

while(1) {
  echo "should display these lines on browser while in infinite loop.<br>";
  flush();
}

or using the `for` loop, they both work fine, and it to make it more accurate i use `ob_flush()` with `flush()`

for($i=0; $i<5000; $i++) {
     echo "should display these lines on browser while in infinite loop.<br>";
     usleep(30000);
     ob_flush();
     flush();
}

they both work fine without ajax

Problem

I'm trying to display the results while PHP script is running, as example.. a really long loop, i want it to echo the results while the page is loading, I searched really a lot through this and i couldn't find the good answer, After googling i found people saying use `ob_flush` from this question .. but it didn't work, as well as enabling the `implicit_flush` from php.ini , still didn't work it only loads when the process is finished, i tried to run a `for` loop like this ``` ob_start(); for($i=0; $i<500; $i++){ echo "hm\n"; ob_flush(); } ob_end_flush(); ``` and still, didn't work.. it shows them all at once My last guess now is that it needs more PHP configurations to enable/disable some stuff, or.. it could also be apache2 configurations ? What are the config settings that are related to this ? settings that needs to be disabled/enabled through Apache or PHP configurations .. P.S. : I'm sure its possible to be done using PHP alone, I saw it done on GoDaddy hosting and saw it on several websites, of them http://www.checker.freeproxy.ru/checker/index.php .. if you try to submit it will show the results normally without using ajax, the website uses PHP and Apache, there's a mystery secret behind this

Original source

Related problems