PHP Flush that works… even in Nginx

前端 未结 8 931
既然无缘
既然无缘 2020-11-30 22:29

Is it possible to echo each time the loop is executed? For example:

foreach(range(1,9) as $n){
    echo $n.\"\\n\";
    sleep(1);
}

Instead

8条回答
  •  旧巷少年郎
    2020-11-30 23:14

    You need to flush the php's buffer to the browser

    foreach(range(1,9) as $n){
        echo $n."\n";
        flush();
        sleep(1);
    }
    

    See: http://php.net/manual/en/function.flush.php

提交回复
热议问题