Page 1 of 1

Included files with php include inherit compression ?

Posted: Sat Dec 27, 2008 5:06 pm
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.

Re: Included files with php include inherit compression ?

Posted: Sat Dec 27, 2008 5:24 pm
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.

Re: Included files with php include inherit compression ?

Posted: Sat Dec 27, 2008 5:30 pm
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");
?

Re: Included files with php include inherit compression ?

Posted: Sat Dec 27, 2008 5:33 pm
by cptnwinky
Exactly, in fact if you do call it again you'll get an error I believe.

Re: Included files with php include inherit compression ?

Posted: Sat Dec 27, 2008 5:43 pm
by lovelf
OK, thank you.

Re: Included files with php include inherit compression ?

Posted: Sat Dec 27, 2008 5:51 pm
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.

Re: Included files with php include inherit compression ?

Posted: Sat Dec 27, 2008 7:36 pm
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