Included files with php include inherit 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
lovelf
Forum Contributor
Posts: 153
Joined: Wed Nov 05, 2008 12:06 am

Included files with php include inherit compression ?

Post by lovelf »

Hi, included files with php include_once inherit the compression stablished by

Code: Select all

ob_start("ob_gzhandler");
in the main file where the included files are being included?

Or the included files do not get compresed?

Thanks to anyone who knows about this.
cptnwinky
Forum Commoner
Posts: 84
Joined: Sat Dec 27, 2008 10:58 am
Location: Williamstown, MA

Re: Included files with php include inherit compression ?

Post by cptnwinky »

It's not the files themselves which are being compressed, just the output. So as long as ob_start("ob_gzhandler"); is set, anything that outputs after it will be compressed.
lovelf
Forum Contributor
Posts: 153
Joined: Wed Nov 05, 2008 12:06 am

Re: Included files with php include inherit compression ?

Post by lovelf »

Including anything inside all of the files included with include_once ?

I do not have to add

Code: Select all

ob_start("ob_gzhandler");
to files that are meant to be included on main files that already have

Code: Select all

ob_start("ob_gzhandler");
?
cptnwinky
Forum Commoner
Posts: 84
Joined: Sat Dec 27, 2008 10:58 am
Location: Williamstown, MA

Re: Included files with php include inherit compression ?

Post by cptnwinky »

Exactly, in fact if you do call it again you'll get an error I believe.
lovelf
Forum Contributor
Posts: 153
Joined: Wed Nov 05, 2008 12:06 am

Re: Included files with php include inherit compression ?

Post by lovelf »

OK, thank you.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Included files with php include inherit compression ?

Post by requinix »

cptnwinky wrote:Exactly, in fact if you do call it again you'll get an error I believe.
I think PHP will just start another compressed output buffer. No errors. But it means some stuff will be compressed twice, which is not good.
cptnwinky
Forum Commoner
Posts: 84
Joined: Sat Dec 27, 2008 10:58 am
Location: Williamstown, MA

Re: Included files with php include inherit compression ?

Post by cptnwinky »

Not to sound like a jerk but your wrong.

Code: Select all

 
<?php
ob_start("ob_gzhandler");
ob_start("ob_gzhandler");
 
echo 'hello world';
 
ob_end_flush();
?>
 
will produce...

Warning: ob_start() [ref.outcontrol]: output handler 'ob_gzhandler' cannot be used twice in /var/www/test.php on line 3
hello world
Post Reply