If mod_deflate is loaded and you can control the apache configuration, then you must let apache do the compression of the output. Performing compression in php will always be slower. Here is my recommended config for your htaccess:
<IfModule mod_deflate.c> SetOutputFilter DEFLATE SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip </IfModule>
I think the blacklist is more efficient in this case, since there are very few types of files that you do not want to compress. Thus, you are sure to compress everything else, even those types of files that you cannot remember to add to the white list.
source share