Re: [SMARTY] Output buffering?
| From: | schultzr at kattare dot com | Date: | Thu, 06 Mar 2003 00:48:08 +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-8421@lists.php.net to get a copy of this message | ||
Quoting James Burrows <james@itsa.me.uk>:
> 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: -
>
Another method is you can specify the ob_gzhandler in a .htaccess file
so it will automatically handle it. just add this to a .htaccess file
php_value output_handler "ob_gzhandler"
if you are using Apache. Which is what i use now instead of handling it
in my php files.
What i used to do is this..
> ------------
> 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;
//
// gzip_compression
//
$do_gzip_compress = FALSE;
$gzip_enabled = FALSE;
if(ini_get("output_handler") == "ob_gzhandler") {
$do_gzip = 0;
$gzip_enabled = TRUE;
}
if($do_gzip)
{
$phpver = phpversion();
if($phpver >= "4.0.4pl1") //ob_gzhandler autodetects if the browser
can handle gzip or not..
{
if(extension_loaded("zlib"))
{
ob_start("ob_gzhandler");
$gzip_enabled = TRUE;
}
}
else if($phpver > "4.0")
{
if(strstr($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip'))
{
if(extension_loaded("zlib"))
{
$do_gzip_compress = TRUE;
$gzip_enabled = TRUE;
ob_start();
ob_implicit_flush(0);
header("Content-Encoding: gzip");
}
}
}
}
>
> ------------
> When I want to display the page: -
> ------------
>
> $smarty->display('main.tpl');
>
> if ($a_config['usingGZip']) {
> $output = ob_get_contents();
> ob_end_clean();
> echo $output;
> }
//
// Compress buffered output if required
// and send to browser
//
if($do_gzip_compress)
{
//
// Borrowed from php.net!
//
$gzip_contents = ob_get_contents();
ob_end_clean();
$gzip_size = strlen($gzip_contents);
$gzip_crc = crc32($gzip_contents);
$gzip_contents = gzcompress($gzip_contents, 9);
$gzip_contents = substr($gzip_contents, 0, strlen($gzip_contents) - 4);
echo "\x1f\x8b\x08\x00\x00\x00\x00\x00";
echo $gzip_contents;
echo pack("V", $gzip_crc);
echo pack("V", $gzip_size);
}
exit;
> Any idea what I'm doing wrong?
>
> 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
>