PHP缓冲输出取决于服务器设置? [英] PHP buffered output depending on server setting?

查看:55
本文介绍了PHP缓冲输出取决于服务器设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码在数据库维护脚本上生成缓冲的输出:

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();

}

虽然在本地Wamp服务器上按预期工作,但显示每次调用该函数时,输出都不会输出到在线Web服务器上:此处仅在脚本结束后才发送输出。
怎么样?

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?

推荐答案

请确保Web服务器上php.ini文件中的输出缓冲已关闭。

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();

您还应该记住,这仍然是特定于浏览器的。浏览器将决定是否显示输出。某些浏览器(例如IE6)在有足够的字符可输出之前不会输出任何东西。

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);

这篇关于PHP缓冲输出取决于服务器设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆