Jump to content

Gzip Compression


Tony M

Recommended Posts

But you can still use gzip compression by adding this to the top of any php file:

 

<?php ob_start("ob_gzhandler"); ?>

 

Thanks but Do this works 100% ok?

 

I read the post at http://www.helionet.org/index/index.php?showtopic=5583 but I didn't really know what are You meaning in: You should be able to get it working with some other (rather complex) .htaccess directives, though. You would need to (using mod_rewrite) pipe all requests into a single PHP file that would GZIP everything as necessary :wacko:

 

Link to comment
Share on other sites

<?php ob_start("ob_gzhandler"); ?>

 

Thanks but Do this works 100% ok?

 

That was one of the options discusssed in that page you posted. I've tried it on a couple of pages of mine and then tested them and they seemed to check ok. Add that piece of code to one of your pages and take it to this test tool:

 

http://www.gidnetwork.com/tools/gzip-test.php

 

I read the post at http://www.helionet.org/index/index.php?showtopic=5583 but I didn't really know what are You meaning in: You should be able to get it working with some other (rather complex) .htaccess directives, though. You would need to (using mod_rewrite) pipe all requests into a single PHP file that would GZIP everything as necessary :wacko:

 

That was posted by djbob and I really didn't look into doing what he said although I'm sure it can be done. I would just add the code I posted to the top of the page instead.

 

This code came from the page you posted. The only difference is they have it in an if statement checking to see if the browser accepts gzip.

 

<?php
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler");
else
ob_start();
?>

 

Link to comment
Share on other sites

I tested the codes:

<?php
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler");
else
ob_start();
?>

and

 

<?php ob_start("ob_gzhandler"); ?>

 

and I tested them with different Gzip compression test tools and ALL WORKED

 

But where to put the code

 <?php
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler");
else
ob_start();
?>

in My pages, because every website tells different places.

 

All My pages codes are like

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <title>My test page</title>
</head>
<body background="images/f.jpg" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
....................................................................................................
...............................................
....................................................................................................
...............................................
....................................................................................................
...............................................
</body>
</html>

so where to put the code (the Gzip code) in My pages? :wacko:

Link to comment
Share on other sites

so where to put the code (the Gzip code) in My pages? :wacko:

 

ALWAYS put it at the top of your page right before the doctype (below).

 

 <?php
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler");
else
ob_start();
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
        <title>My test page</title>
</head>

 

You'll never see that php code in the source of the page. Just a space before the doctype. And I guess you already know that the page has to have a .php extension.

 

Link to comment
Share on other sites

Can I use <?php include("mypage.php"); ?> on every top of My pages and put in mypage.php the Gzip code, so that when I want to disable Gzip on all My pages, I only modify one page (I tested it and worked but I do not know if using php include for the Gzip code can make ERRORS or server errors....) :)

Link to comment
Share on other sites

As long as you don't remove mypage.php. If the include() function can't find a page it will generate an error. So if you want to disable gzip you would need to comment out the gzip code on mypage.php like this:

 

<?php

/*

if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler");
else
ob_start();

*/

?>

 

Link to comment
Share on other sites

  • 2 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...