PHP Flush/ob_flush not working

前端 未结 7 2326
情深已故
情深已故 2020-11-27 07:03

I\'ve tried several attempts at getting my flush and ob_flush to work. I\'ve tried setting the ini to allow buffering, I\'ve tried using several different functions I found

7条回答
  •  广开言路
    2020-11-27 07:21

    The idea here is to disable output buffering, not enable it. As its name says, output buffering will save the output to memory and display it at the end of the script, or when explicitly asked for it.

    That being said, you don't have to flush explicitly for every output. Use the following, before displaying any output, and then you won't have to bother flushing every time you echo something:

    ob_implicit_flush(true);
    ob_end_flush();
    

    Per example:

    ob_implicit_flush(true);
    ob_end_flush();
    
    for ($i=0; $i<5; $i++) {
       echo $i.'
    '; sleep(1); }

    Will output, 0 to 4, with each being displayed every second.

提交回复
热议问题