PHP Flush All Levels of Output Buffering

我的未来我决定 提交于 2020-01-11 05:44:05

问题


I'm trying to implement a simple Http Response class that implements Http Streaming (or Chunked-Encoding). For this to be possible, I need to set output_buffering = Off in the php.ini, and flush the output at certain intervals.

PHP does a good job of this automatically - except for the actual flushing mechanism. I've gotten it to work, but I'm not sure if it's overboard. I want to know how to flush each level of output buffering at once, without calling a billion functions (I'm not sure which ones are redundant on which environments / in which scenarios).

    while (ob_get_level())
    {
        ob_end_flush();
    }

    // print the buffer

    flush();
    ob_flush();

Is this overkill?


回答1:


You don't need ob_flush() and ob_end_flush(). Your while loop is sufficient.

You should also look at: http://us.php.net/manual/en/function.ob-implicit-flush.php

Your need for flush() after ob_end_flush() depends on how you set this function.



来源:https://stackoverflow.com/questions/7549347/php-flush-all-levels-of-output-buffering

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!