PHP buffered output depending on server setting?

◇◆丶佛笑我妖孽 提交于 2019-12-13 16:33:03

问题


I'm using the following code to produce buffered output on a db maintenance script:

function flush_buffers($string){
    echo $string;
    ob_end_flush();
    ob_flush();
    flush();
    ob_start();

}

While this works as expected on my local Wamp server, showing output each time the function is invoked, it doesn't on the online web server: here the output is sent only once the script has ended. How is that?


回答1:


Make sure output buffering is off in your php.ini file on your web server.

You also don't have to flush manually every time, you can make use of:

ob_implicit_flush(true);
ob_end_flush();

You should also remember that this is still browser specific. The browser will decide whether to show the output. Some browsers (for example IE6) won't output anything until it has enough characters to output.

The following will turn off everything that could cause unwanted output buffering.

@apache_setenv('no-gzip', 1);
@ini_set('zlib.output_compression', 0);
@ini_set('implicit_flush', 1);
for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
ob_implicit_flush(1);


来源:https://stackoverflow.com/questions/6385676/php-buffered-output-depending-on-server-setting

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