Re: [SMARTY] Output buffering?
| From: | messju mohr | Date: | Wed, 05 Mar 2003 22:23:02 +0000 |
| Subject: | Re: [SMARTY] Output buffering? | ||
| References: | 1 2 3 4 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-8418@lists.php.net to get a copy of this message | ||
Hello,
On Wed, Mar 05, 2003 at 08:20:31PM -0000, James Burrows wrote:
> Hi,
>
> I can't seem to get this to work. When this code is called (and output
> buffering is on), a blank page is returned to the browser. I get my
> expected page, however, when not using output buffering: -
>
>
> ------------
> Before I assign vars to smarty: -
> ------------
>
> $a_config['usingGZip'] = false;
> if (strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) {
> if (extension_loaded('zlib')) {
> $a_config['usingGZip'] = true;
> ob_start('ob_gzhandler');
> }
> }
> $smarty = new Smarty;
>
> ------------
> When I want to display the page: -
> ------------
>
> $smarty->display('main.tpl');
>
> if ($a_config['usingGZip']) {
> $output = ob_get_contents();
> ob_end_clean();
> echo $output;
> }
>
> Any idea what I'm doing wrong?
i tried your example and looked at the traffic that is intechanged
between webserver and -browser.
i used an old galeon-1.2.5, but any browser may behave errornously
here. the problem is that a header stating "Content-Encoding: gzip" is
sent to the browser, but the content is not gzipped at all.
if i comment out
# $output = ob_get_contents();
# ob_end_clean();
from your example everything works fine and the content sent looks gzipped
and the browser shows the page correct.
there is an annotation on
http://www.php.net/manual/en/function.ob-gzhandler.php
: if you call ob_end_clean() after ob_start("ob_gzhandler"), the
: "Content-Encoding: gzip" header will still get sent (assuming the
: browser supports the encoding). if you don't call ob_start() again
: with the ob_gzhandler callback function, the output will not be
: compressed, but the header will say it is. this causes mozilla (as of
: build 2002032808) to display a blank page.
maybe this is related to the same problem.
so just starting the ob_gzhandler, but not ending it, may be the
solution, but looks a bit ugly in the source (like an unclosed fopen())
:-)
have fun
messju
> Cheers,
> James
>
> ----- Original Message -----
> From: "Hinrich Donner" <hd@tiro.de>
> To: <smarty-general@lists.php.net>
> Sent: Tuesday, March 04, 2003 1:17 PM
> Subject: Re: [SMARTY] Output buffering?
>
>
> Hi,
>
> include 'Smarty.class.php';
> ob_start('ob_gzhandler');
> $smarty =& new Smarty();
> $smarty->Display('my.tpl');
> $output = ob_get_contents();
> ob_end_clean();
>
> echo $output;
>
> On Tuesday 04 March 2003 14:01, James Burrows wrote:
>
> > Hi there,
> >
> > Is it possible to perform output buffering using smarty? I'd like to
> gzip
> > my output before sending it to the browser.
> >
> > Thanks,
> > James
>
> --
> Hinrich Donner
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--
Torx-Schrauben: Hände-Weg-Schrauben
nach Marc Habers Kollegen