PHP缓冲输出取决于服务器设置?

编程入门 行业动态 更新时间:2024-10-28 16:23:24
本文介绍了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缓冲输出取决于服务器设置?

本文发布于:2023-11-12 19:33:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582334.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:服务器   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!