JediWizard has asked for the wisdom of the Perl Monks concerning the following question:

Wise Monks, I have a question about perl and CGI applications.

I have a CGI application which dynamically generates very large pages (up to arround 20 mb of html). Naturally this can take some time, not only to generate, but also to transmit across the web, and display on the client side. I am currently investigating ways to reduce the size of the HTML, but that is not what I want to ask here. I know there is a mod for apache which will gzip the output from a script, in a way which the browser will recognise and unzip automagically. I, however, have had no success in getting this plug-in to function properly. My question is: Is there a way to do this entirely on the perl side? I would like to build a string in perl, gzip it, and send it to the browser and have it automagically unzipped and displayed by the client browser. I'm sure there are modules on CPAN to gzip a string, but is there some header I need to send in order to tell the browser to unzip the data before trying to display it? I am working in perl 5.6.1 on Red Hat linux 8.0, with apache 1.27, and the application is designed to work in IE 5.0 and later.

May the Force be with you

Replies are listed 'Best First'.
Re: OFT: Gzipping output from a CGI
by perrin (Chancellor) on Nov 30, 2004 at 21:19 UTC
    If you can use mod_perl, there are good tools for it. Check out this page.

      That page Rocks!!!! Thank you much... You ROCK!!!!!

      May the Force be with you
Re: OFT: Gzipping output from a CGI
by gaal (Parson) on Nov 30, 2004 at 21:04 UTC
    Let apache handle it. Look for mod_gzip.

    (You can also gzip things on the fly with PerlIO::gzip, but I think that requires a newer perl.)

      I would perfer to let apache handle it, however, I am not the Apache expert in my company, and the resident apache expert has not been able to get a working compliation of apache with mod_gzip. Without that, I'd like to do it in perl, and seems there must be a way to tell the browser that the content is zipped. if "mod_gzipp" can do it, there must be a way to do it with perl, i.e. a header that tells the browser to unzip the output.

      May the Force be with you
        There's also mod_deflate your apache person can try.

        If you want to see the header, use something like snoop or tcpdump or Firefox's Live HTTP Headers extension on a site that uses compressed pages. Here's one. Then you have to write the header soon enough in your CGI; and then compress everything following (once again, with the IO layer it'd be easier, as well as better since you don't have to wait until you have all the data before sending it).

Re: OFT: Gzipping output from a CGI
by Thilosophy (Curate) on Dec 01, 2004 at 08:07 UTC
    If you cannot use mod_gzip/mod_deflate and are using plain old CGI, you want to have a look at CGI::Compress::Gzip on CPAN.

    Two questions:

    1. Do browsers handle 20 MB HTML pages well?
    2. What is OFT?
Re: OFT: Gzipping output from a CGI
by etcshadow (Priest) on Nov 30, 2004 at 21:35 UTC
    Also, if you're using some sort of application server for your CGI, it may have built in facility for this. Apache::ASP, HTML::Mason and Apache::AxKit (for example) all have features to support this with little more than a flick of the switch... quite possibly others, too.
    ------------ :Wq Not an editor command: Wq