Solution based on flush of when output cannot be sequentially

  • 2020-06-23 00:02:55
  • OfStack

If you are under linux, first confirm whether to add ob_start() and ob_flush().

ob_start();
for ($i=1; $i<=10; $i++) {
        echo $i."<br />\n";
        ob_flush();
        flush();
        usleep(500000);
}

If it still doesn't work, prefix the code with a header

header("Content-Type:text/html;charset=utf8;");
ob_start();
for ($i=1; $i<=10; $i++) {
        echo $i."<br />\n";
       ob_flush();
    flush();
        usleep(500000);
}

Related articles: