ob_get_level()从1级开始

问题描述:

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.

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