user1032478
user1032478

Reputation:

How to print out whether the current web page is compressed?

I am using a .htaccess file to compress my .php , .css and .js files. What I want to do is to echo out in my footer is GZIP enabled or not.

For example if its not enabled by the server to echo out GZIP is not enabled or of it is to echo out GZIP is enabled.

I've looked around the net and couldn't find a php script doing that. I thought I could make it work with ini_get() but obviously unsuccessfully.

Can someone give me a tip?

Thanks :)

Upvotes: 0

Views: 174

Answers (1)

hakre
hakre

Reputation: 198219

I have problems to understand your question. If you want to find out if the gzip encoding of your server and php configuration works, you need to check that with an additional program sending requests to the URLs in question and check if gzip is used. One such tool is curl on the commandline:

$ curl --compress --raw -i URL

Example:

  $ curl --compress -I https://stackoverflow.com/questions/8029168/show-is-my-gzip-enabled-on-my-webpage

  HTTP/1.1 200 OK
  Cache-Control: public, max-age=18
  Content-Length: 8683
  Content-Type: text/html; charset=utf-8
*****************************
* Content-Encoding: deflate *
*****************************
  Expires: Sun, 06 Nov 2011 18:21:05 GMT
  Last-Modified: Sun, 06 Nov 2011 18:20:05 GMT
  Vary: *
  Date: Sun, 06 Nov 2011 18:20:46 GMT

See the line I highlighted:

Content-Encoding: deflate 

it signals that something gzip is active. See RFC2616 - HTTP/1.1 14.11 Content-Encoding for the full meaning of this line.

More information is available in a related question/answer: PHP Output buffering, Content Encoding Error caused by ob_gzhandler?.

If that's not your issue maybe Gzip a website with inline PHP code is helpful.

Upvotes: 1

Related Questions