ob_get_level()从级别1开始 [英] ob_get_level() starts at level 1

查看:164
本文介绍了ob_get_level()从级别1开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

输出缓冲有一些问题.主要是,我尝试使用ob_gzhandler回调运行输出缓冲,但是它一直在告诉我它使用了不受支持的压缩类型.一切都已启用,我相信问题是在脚本开始时运行ob_get_level()会产生1级.php.ini的output_buffering设置为4096.

Having a few problems with output buffering. Mainly, I'm trying to run output buffering with the ob_gzhandler callback, but it keeps telling me its using an unsupported compression type. Everything is enabled, and I believe the problem is that running ob_get_level() at the start of my script produces a level of 1. php.ini has my output_buffering set to 4096.

如果我运行类似的内容

while(ob_get_level() > 0){
   ob_end_clean();
}

然后,我可以使用ob_gzhandler回调成功运行ob_start().但是我想知道这是否应该是一个问题.在我的脚本执行过程中,我会在各个时间点调用ob_clean(),因为我避免了堆叠过多的缓冲区,因为我读到这可以提高性能.我只是不确定我应该在这里做什么.

Then I can successfully run ob_start() with the ob_gzhandler callback. But I'm wondering if it should be a problem. During my script I make calls to ob_clean() at various points as I'm avoiding stacking too many buffers as I've read this can increase performance. I'm just unsure as to what I should be doing here.

干杯.

推荐答案

默认情况下,您已启用输出缓冲(请参见

You have output buffering enabled by default (see the docs) - that basically means that every PHP script starts with ob_start().

如果要禁用所有PHP脚本的默认OB,请在php.ini中设置output_buffering = Off.

If you want to disable the default OB for all PHP scripts, in your php.ini, set output_buffering = Off.

如果只想为此特定脚本禁用默认OB,请使用while循环-完全正确.

If you only want to disable the default OB for this specific script, use the while loop - it's quite correct.

关于 ob_clean -您确定要吗删除缓冲区中的输出? IMO并没有真正的必要,除非您看到大量的缓慢页面加载.不必担心进行优化(至少现在不是).

As for the ob_clean - are you sure you want to delete the output that's in your buffer? IMO it's not really necessary, unless you are seeing significant slow page loads. Don't worry about optimizing that (at least not now).

这篇关于ob_get_level()从级别1开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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