'ob_gzhandler' conflicts with 'zlib output compression'

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

'ob_gzhandler' conflicts with 'zlib output compression'

Post by JAM »

Problem:

Code: Select all

Warning: ob_start(): output handler 'ob_gzhandler' conflicts with 'zlib output compression' in /development/test/admin_functions.php on line 550
I'd like to have this explained abit, as I'm not sure on how to use either of the two. Which setting is the prefered when it comes to output compression?

Thanks in advance.
evilMind
Forum Contributor
Posts: 145
Joined: Fri Sep 19, 2003 10:09 am
Location: Earth

Post by evilMind »

Check your php.ini and see if you have zlib.output_compression on. ( 1 , true, etc) If you have it turned on then you will need to turn it off (either by ini_set() or by changing the php.ini file) to use ob_gzhandler().
However, if zlib.output_compression is on, per php.net, it's better to use zlib.output_compression than it is to use ob_gzhandler().
As far as the usage of these....



ob_start(); is used to turn output buffering on. Nothing will be sent to the client until you flush the buffer. ( ob_flush(); ) The ob_gzhandler() is simply a callback function for ob_start... eg, ob_start('ob_gzhandler') so when you do flush the buffer it will send the contents back compressed (***ONLY if the client browser sent a header stating that it can accept compressed data).

Hope that clears some of ob_start() and ob_gzhandler() up for you.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Code: Select all

output_buffering = Off
;output_handler =
zlib.output_compression = On
I was debugging a piece of script when it happened, and to me it looks like I only have zlib set on, hence I'm wondering. I changed my debugging computer at that time by coinsidence, and does not have that piece of code to examine.

So, without being able to see for myself, does the problem occur only if calling ob_start('ob_gzhandler') when it's actually turned off?
evilMind
Forum Contributor
Posts: 145
Joined: Fri Sep 19, 2003 10:09 am
Location: Earth

Post by evilMind »

Actually, if you are going to use ob_start('ob_gzhandler') You cannot have zlib.output_compression = On.
Reason being is because ob_gzhandler does the same thing as zlib.output_compression does (it compresses the output).

So if your php.ini has "zlib.output_compression=On" you only need to use ob_start(); to compress the output.
However, if your php.ini has "zlib.output_compression=Off" you need to use some other means of to compress the output (which is what ob_gzhandler is for ... those who can't change thier php.ini and need to use output compression)

Oh yeah, almost forgot, the line in your php.ini "output_buffering = off" means simply that: by default output buffering is turned off

if all else fails try this:
before you call ob_start

Code: Select all

<?php
 ini_set('zlib.output_compression' , '0');
 ob_start('ob_gzhandler');
 ... code ..
 ob_flush();
?>

 - OR -

<?php
 ob_start();
 ... Code ...
 ob_flush();
?>
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

Post by Cruzado_Mainfrm »

woa, i have used ob_start before and i haven't needed to use ob_flush() at the end... why is that?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

evilMind
Thanks, and yes, I think I understood that part abit more clear now.

My main concern is that I'm rewriting parts of a pre-existing application aswell as adding modules to it. I had no idea of what it used for compression (I dont really care at that state), so I was rather curious when I first ran it.

The only explanation i can come up with is that I'm using zlib, and the previous writer where using gz. It's rather annoying that either the PHP parser cant override this automaticly (if both is set = On, use the first one, skip the other). or that people can verify the php.ini settings using ini_get() before using one or the other.

Cruzado
I think that if you use ob_start() without ending buffering with ob_end_flush()/ob_end_clean() it will still be flushed when the script ends. Don't hold it against me tho. ;)
I always end it wherever I use it, as I feel that's the correct way to do it...
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

Post by Cruzado_Mainfrm »

that's a good point, but why would one do it if anyways at the end it's going to be done? it's like setting variables and unsetting them before the script ends :wink: isn't it? but i get your point :D it's like writing Strict XHTML
markbeadle
Forum Commoner
Posts: 29
Joined: Tue Dec 02, 2003 2:50 am
Location: Aachen, Germany

Post by markbeadle »

Cruzado_Mainfrm wrote:woa, i have used ob_start before and i haven't needed to use ob_flush() at the end... why is that?
ob_flush is automatically called at the end of the php script. Although it is not necessary it is a good idea to always put it in for readability.
Post Reply