Quantcast

Use ob_gzhandler with ZF

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Use ob_gzhandler with ZF

Ralf Eggert
Hi,

I wonder if anyone has used the ob_gzhandler with the Zend Framework
yet. How should the usage of ob_gzhandler be implemented when using
Zend_Controller? Will this usage take of the very few browsers that
don't accept gzip compressed files?

Thanks and best regards,

Ralf
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Use ob_gzhandler with ZF

Jack Sleight
Hi Ralf,
I've not used ob_gzhandler with ZF specifically, however I would imaging
it should be as simple a wrapping your call to the front controllers
dispatch method in ob_start('ob_gzhandler'); and ob_end_flush();. This
will only compress responses where the browser said it could accept
gz-encoding.

As far as I know, the Zend_Controller_Response_Http doesn't have built
in support for ob_gzhandler.

However, with my applications I set up gz-encoding in Apache instead,
which has the advantage of being applied to any text/html response, or
any other mime type for that matter. Add this to your .htaccess or
httpd.conf

AddOutputFilterByType DEFLATE text/html
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent

Personally I compress all of these types:

text/html text/css application/x-javascript text/plain text/xml text/csv
text/x-component

Hope that helps,

Ralf Eggert wrote:

> Hi,
>
> I wonder if anyone has used the ob_gzhandler with the Zend Framework
> yet. How should the usage of ob_gzhandler be implemented when using
> Zend_Controller? Will this usage take of the very few browsers that
> don't accept gzip compressed files?
>
> Thanks and best regards,
>
> Ralf
>  

--
Jack
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Use ob_gzhandler with ZF

Jonathan Kushner-2
You might want to check out YUI Also.

http://developer.yahoo.com/performance/rules.html#gzip

Also, these can also help you with Jack's original set...

    # Insert filter
    #SetOutputFilter DEFLATE
    # Netscape 4.x has some problems...
    #BrowserMatch ^Mozilla/4 gzip-only-text/html
    # Netscape 4.06-4.08 have some more problems
    #BrowserMatch ^Mozilla/4\.0[678] no-gzip
    # MSIE masquerades as Netscape, but it is fine
    #BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    # Don't compress images
    #SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
    # Make sure proxies don't deliver the wrong content
    #Header append Vary User-Agent env=!dont-vary

-----Original Message-----
From: Jack Sleight [mailto:[hidden email]]
Sent: Sunday, May 25, 2008 2:49 AM
To: Ralf Eggert
Cc: [hidden email]
Subject: Re: [fw-mvc] Use ob_gzhandler with ZF

Hi Ralf,
I've not used ob_gzhandler with ZF specifically, however I would imaging

it should be as simple a wrapping your call to the front controllers
dispatch method in ob_start('ob_gzhandler'); and ob_end_flush();. This
will only compress responses where the browser said it could accept
gz-encoding.

As far as I know, the Zend_Controller_Response_Http doesn't have built
in support for ob_gzhandler.

However, with my applications I set up gz-encoding in Apache instead,
which has the advantage of being applied to any text/html response, or
any other mime type for that matter. Add this to your .htaccess or
httpd.conf

AddOutputFilterByType DEFLATE text/html
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent

Personally I compress all of these types:

text/html text/css application/x-javascript text/plain text/xml text/csv

text/x-component

Hope that helps,

Ralf Eggert wrote:

> Hi,
>
> I wonder if anyone has used the ob_gzhandler with the Zend Framework
> yet. How should the usage of ob_gzhandler be implemented when using
> Zend_Controller? Will this usage take of the very few browsers that
> don't accept gzip compressed files?
>
> Thanks and best regards,
>
> Ralf
>  

--
Jack

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Use ob_gzhandler with ZF

Ralf Eggert
In reply to this post by Jack Sleight
Hi Jack and Jonathan,

thanks for your hints. Unfortunately using .htaccess or httpd.conf is
not possible at the moment (it's complicated). But I will now use the
simple wrapping style as you suggested.

Thanks and best regards,

Ralf
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Use ob_gzhandler with ZF

Jonathan Kushner-2
How are you able to route then?

-----Original Message-----
From: Ralf Eggert [mailto:[hidden email]]
Sent: Tuesday, May 27, 2008 7:47 AM
To: [hidden email]
Subject: Re: [fw-mvc] Use ob_gzhandler with ZF

Hi Jack and Jonathan,

thanks for your hints. Unfortunately using .htaccess or httpd.conf is
not possible at the moment (it's complicated). But I will now use the
simple wrapping style as you suggested.

Thanks and best regards,

Ralf

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Use ob_gzhandler with ZF

Ralf Eggert
Hi Jonathan,

> How are you able to route then?

Like I wrote, it's complicated. I can use .htaccess files but was not
able to use mod_gzip or deflate until now. But a few hours ago I got a
message from the provider, how to use mod_gzip now. So problem will be
solved soon.

Thanks and best regards,

Ralf
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Use ob_gzhandler with ZF

AmirBehzad Eslami
I've written a plugin to compress ZF-generated content.
It first removes unnecessary white spaces, then gzips the content (if browser can handle that).
Here it is:

<?php

require_once 'Zend/Controller/Plugin/Abstract.php';

class My_Plugin_CompressResponse extends Zend_Controller_Plugin_Abstract
{

    public function postDispatch(Zend_Controller_Request_Abstract $request)
    {
   
        $content = $this->getResponse()->getBody();

        $content = preg_replace(
            array(
                '/(\x20{2,})/',   // extra-white spaces
                '/\t/',           // tab
                '/\n\r/'          // blank lines
            ),
            array(' ', '', ''),
            $content
        );

        // if the browser does not support gzip, serve the stripped content
        if (@strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') === FALSE) {
            $this->getResponse()->setBody($content);
        }
        else {
            header('Content-Encoding: gzip');
            $this->getResponse()->setBody(gzencode($content, 9));
        }

    }

}
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Use ob_gzhandler with ZF

jonnott
In reply to this post by Jack Sleight
Ok, forgive me for digging up an ancient thread here, and for heading slightly off-topic (although I am trying to shoe-horn this stuff into a ZF context):

So, this looks to be basics of the de-facto (apache.org) recommended mod_deflate .htaccess setup:

AddOutputFilterByType DEFLATE text/html
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent

But, my question is, do we even need the BrowserMatch stuff here, and the adding of 'User-Agent' to the 'Vary' header (which in itself must cause huge potential-for-caching inefficiency for proxies/network-level-caches)??

Seems all they're doing is saying "don't gzip for old Mozilla 4.0 browsers, unless they're actually IE". But are any of these non-IE old Mozilla 4.0 browsers still in widespread use, even in the slightest? Is Opera fully gzip friendly?

Also, what's the deal with the rumoured don't-like-gzip errors with certain versions of IE 6.0 that occur intermittently? These rules don't seem to care what IE version it is, so are there any real issues? And what about IE <= 5.5? Not that anyone even makes their sites work in such antiques these days!

What I'm asking, in a nutshell, is why can't I just do this:

AddOutputFilterByType DEFLATE text/html

..and let mod_deflate automatically take care of choosing whether to gzip based solely on the 'Accept-Encoding' header, and automatically adding 'Vary: Accept-Encoding' if it gzips?

Jonny
Loading...