1

I was sniffing the response header of one my sites and apparently is not using http compression to deliver responses because I'm not seeing the Content-Encoding: gzip in the response header.

But the weird thing is that phpinfo() shows me HTTP_ACCEPT_ENCODING: gzip,deflate,sdch

Im using a rackspace cloud site (shared hosting, cant access httpdconfig), and I really want to activate http compression but the support guys over there tells me that if the phpinfo() says it, its already on.

thanks.!

gansodesoya
  • 113
  • 2

2 Answers2

0

HTTP_ACCEPT_ENCODING means the browser accepts those encodings. It doesn't mean the server is sending those encodings - it's a client side header.

ceejayoz
  • 32,910
  • 7
  • 82
  • 106
0

What you should do is add this php code to the very begenning of any PHP files that you want to use compression:

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

Often times there is a header file that is included by all files, a good example is the database config file. As long as this line of code is added before your program does a print() or echo() then you are golden.

This will buffer all of the output that the PHP page builds, and then gzip's it before sending it to the browser. If you are just serving flat html files, then you could write a simple PHP access page to read the .html file and print it:

<?php
   ob_start("ob_gzhandler");
   print(file_get_contents("./html/somefile.html")); 
?>
Rook
  • 2,655
  • 6
  • 27
  • 35