Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.!

share|improve this question

2 Answers 2

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")); 
?>
share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.