ob_get_level() starts at level 1

我的未来我决定 提交于 2019-11-28 07:34:38

问题


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.

If I run something like:

while(ob_get_level() > 0){
   ob_end_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.

Cheers.


回答1:


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

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

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

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



来源:https://stackoverflow.com/questions/3641598/ob-get-level-starts-at-level-1

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