How to check if gzip compression is enabled with PHP?

Enough (function_exists('ob_gzhandler') && ini_get('zlib.output_compression')) ?

I want to check if the site serves compressed pages on one of the pages :)

+4
source share
3 answers

For PHP, they will do their best.

However, if you are referring to page compression back to clients, you will also need to check its inclusion in apache (if you use apache, you will need mod_gzip.c or mod_deflate.c modules).

For example: # httpd -l (apache 2)

I also noticed a mention of the need to implement .htaccess overrides in the past:

 #compress all text & html: AddOutputFilterByType DEFLATE text/html text/plain text/xml # Or, compress certain file types by extension: <Files *.html> SetOutputFilter DEFLATE </Files> 
+3
source

FROM

 <?php phpinfo(); ?> 

You can find out if the module is loaded

or

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

You can check if compression is enabled on a specific page.

With those that you see, is there enough compression for you.

+4
source

you can do it programmatically with php:

 if (count(array_intersect(['mod_deflate', 'mod_gzip'], apache_get_modules())) > 0) { echo 'compression enabled'; } 

This, of course, is not super reliable, because there may be other compression modules ...

+1
source

Source: https://habr.com/ru/post/1397837/


All Articles