Speed up your pages. Use less bandwidth.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jayeff
    Confirmed User
    • May 2001
    • 2944

    #1

    Speed up your pages. Use less bandwidth.

    A client just installed this on his site and reported a 42K (80%) reduction in the data delivered when visiting his main page. That makes for faster load times and a major bandwidth saving.

    This method utilizes gzip which is available by default on most servers these days. It can be used on any type of site, but since images are not gzipped, the main benefit is for sites using lots of text and/or code. Blogs are obviously prime candidates and also the reason I went this route rather than mod_gzip. It causes problems with WP-Cache, as does telling WordPress to deliver gzipped pages.

    I also wanted a solution which would gzip all the pages on a site, not only php pages generated by WordPress, but also static HTML pages. I did not want to have to add code to every page. And I didn't want any problems with Zend. This appears to satisfy all those conditions.

    Save this code to a file called compress.php:
    Code:
    <?php
    $file = $_SERVER["PATH_TRANSLATED"];
    readfile($file);
    ?>
    Save this code to a file called begin_gzip.php:
    Code:
    <?php ob_start("ob_gzhandler"); ?>
    Save this code to a file called end_gzip.php:
    Code:
    <?php ob_flush(); ?>
    FTP all three files to your root directory and then modify the paths in these lines and add them to .htaccess in your root directory:
    Code:
    AddHandler compress .html
    Action compress /compress.php
    php_value auto_prepend_file /full_server_path_to_your_root_directory/begin_gzip.php
    php_value auto_append_file /full_server_path_to_your_root_directory/end_gzip.php
    That's it. Go to http://whatsmyip.org/mod_gzip_test/ put in your site URL and see if it is working.

    I have tested this on several sites for more than a month, primarily sites using WordPress 2.1 and WP-Cache2, plus a variety of other plugins and scripts. The only glitch seems to be with scripts such as Comus which have slow-running routines for things like creating thumbnails. What happens is that you click the button to begin the process and you will not see an intermediate page (telling you the work is in progress). Everything functions as it should, but you will not see anything until the next page comes up when the job is complete.

    As far as your surfers are concerned, the site runs normally and there are no browser incompatibilities. If an old browser doesn't understand gzip, it simply gets "regular" code and text. There may be a very small-payoff in processor load, but unless your server is close to the edge, nothing that will make any practical difference.

    If you follow the instructions and it does not work, beyond checking that your server has gzip (plain gzip, not mod_gzip) enabled, I should assume you are using something it doesn't like and give up. But it will only take 5 minutes to find out and if all is okay, the savings can be significant.
  • Boobs
    Confirmed User
    • Aug 2006
    • 7875

    #2
    some really techie stuff here

    Join the fucking best in big tit sponsors!!!

    Comment

    • jayeff
      Confirmed User
      • May 2001
      • 2944

      #3
      Originally posted by Boobs
      some really techie stuff here
      It's actually about as complicated as following the instructions on a packet of Jello. But yes, I don't imagine this is a thread which will stay on the front page for long

      Comment

      • RawAlex
        So Fucking Banned
        • Oct 2003
        • 9465

        #4
        of course, you could just move on to apache2 and stop worrying.

        It would also be interesting to see what the implications are of this strategy on CPU usage. It would appear that you are handing your server a ton of processing work to do to keep serving pages. At what point do you run out of processing before you run out of bandwidth?

        Comment

        • Calvinguy
          Confirmed User
          • Oct 2002
          • 1752

          #5
          Can external css files be compressed in some way?

          Comment

          • tASSy
            Spread The Pink!
            • Nov 2004
            • 8229

            #6
            Originally posted by RawAlex
            of course, you could just move on to apache2 and stop worrying.

            tassy*PINK
            * ICQ ~ 318*097*066 *


            Comment

            • jayeff
              Confirmed User
              • May 2001
              • 2944

              #7
              Originally posted by RawAlex
              of course, you could just move on to apache2 and stop worrying.
              Apache2, like the most recent versions of mySQL and to a lesser extent, PHP, tend to solve some problems while introducing others: at least until everyone catches up with them. For that reason, I must admit I tend to upgrade underlying stuff slowly.

              Originally posted by RawAlex
              It would also be interesting to see what the implications are of this strategy on CPU usage. It would appear that you are handing your server a ton of processing work to do to keep serving pages. At what point do you run out of processing before you run out of bandwidth?
              Gzip has been shown to be an efficient process and if you think about the whole cycle of delivering content, not merely about the actual compression, using gzip isn't all downside. A lot will depend on what else is in the mix, but as I noted originally (and one of my test servers is a very humble P3) I haven't seen anything negative so far and I suspect you would already be close to overloaded for the extra work this generates to become critical.

              Comment

              • uno
                RIP Dodger. BEST.CAT.EVER
                • Dec 2002
                • 18450

                #8
                will that work in conjunction with mod_gzip?
                -uno
                icq: 111-914
                CrazyBabe.com - porn art
                MojoHost - For all your hosting needs, present and future. Tell them I sent ya!

                Comment

                • jayeff
                  Confirmed User
                  • May 2001
                  • 2944

                  #9
                  Originally posted by uno
                  will that work in conjunction with mod_gzip?
                  No idea. I specifically wanted to avoid mod_gzip although somewhat embarrassingly, I can't even remember why now. Anyway I checked it out first and there was at least one of the requirements I mentioned in my first post, that it didn't meet.

                  The main thing is this takes a couple of minutes to set up and as long as it takes to delete those lines from htaccess, if it doesn't work and no damage done.
                  Last edited by jayeff; 02-18-2007, 10:34 AM.

                  Comment

                  • NoWhErE
                    Too lazy to set a custom title
                    • Sep 2005
                    • 10583

                    #10
                    Do you think we could apply that to GFY? Things are loading so slowly lately :P
                    skype: lordofthecameltoe

                    Comment

                    • rotterdammer
                      Confirmed User
                      • Feb 2006
                      • 1523

                      #11
                      very cool tips you are telling her

                      Comment

                      • fuzebox
                        making it rain
                        • Oct 2003
                        • 22359

                        #12
                        Originally posted by jayeff
                        Apache2, like the most recent versions of mySQL and to a lesser extent, PHP, tend to solve some problems while introducing others: at least until everyone catches up with them. For that reason, I must admit I tend to upgrade underlying stuff slowly.
                        I'm the same way, every time I try to go with Apache2 on a new box it lasts for about a day before I get frustrated and go back to 1.3.

                        Comment

                        • Phil21
                          Confirmed User
                          • May 2001
                          • 993

                          #13
                          Regarding the CPU use comment...

                          On 95&#37;+ of all dedicated servers (likely more, but I don't care to try to filter statistics on a sunday afternoon...) CPU is basically idle. Customers have unfortunately been duped by crap marketing from hosting providers basically telling them MORE BIGGER BETTER with regards to CPU, and thus we have to compete in that arena (even though during pre-sales, we absolutely try to point out that the dual xeon for your 2mbit of traffic is likely overkill).

                          In almost all cases, your largest bottleneck will be disk I/O. Period. Gzip in this manner helps with that, as the files are smaller. mod_gzip trades cpu use for bandwidth savings - so it's a tradeoff you have to decide if it's worth it or not.

                          That said... If you can use mod_gzip instead of this solution - do so. It will be a huge savings in CPU, probably by a factor of 10 or more. However, as Jayeff mentions mod_gzip doesn't play nicely with some applications making this a great solution for those PHP pages that you otherwise couldn't gain bandwidth savings on.

                          Good post!
                          Quality affordable hosting.

                          Comment

                          Working...