views:

36

answers:

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.

+1  A: 

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

Piskvor
Yes, I believe I do. It's set as: output_buffering = 4096 (which I said above). What I'm getting at, is should I leave that as it is, and simply run the loop I have above so that I can start output buffering ob_gzhandler?
Jason Lewis
@Jason Lewis: That's up to you. I'd probably leave the default OB on for all scripts, and terminate it with the `while` loop in cases where I wanted to use my own.
Piskvor
I was meant to say I use ob_get_clean() in a few places, to store output in a few variables and eventually it is flushed. Is this a good way of doing it, or should I start a new buffer for each place where I want to capture output and use ob_get_flush() instead?
Jason Lewis
It actually doesn't seem to be working when I run ob_start('ob_gzhandler') and then use ob_clean(). Seems to display the unsupported compression type. So I am using a master buffer (ob_start()), then capturing the required outputs throughout my application and cleaning the buffer afterwards. Then when it comes to display the final output I end the master buffer and start a new buffer with the compression, and it seems to be working.
Jason Lewis
yeah, ob_get_clean is OK.
Piskvor