PHP Flush that works… even in Nginx

前端 未结 8 952
既然无缘
既然无缘 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:22

    You can accomplish this by flushing the output buffer in the middle of the loop.

    Example:

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

    Note that your php.ini settings can affect whether this will work or not if you have zlib compression turned on

提交回复
热议问题