1
votes

I'm using .htaccess provided by http://html5boilerplate.com/ which is correctly compressing the .html, .css, & .js files but I have not been able to get the .php files to compress unless I add <?php if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ?> to the top of the page. The last thing I want to do is add that line to a hundred plus pages.

I've been using the following two sites to verify the gzip compression:

The following suggestions have not worked either:

I've also tried the following (http://perishablepress.com/fast-effective-php-compression/):

<?php // placed in a gzip_start.php file
ob_start("ob_gzhandler");
?>

<?php // placed in a gzip_stop.php file
ob_flush();
?>

# Placed in the .htaccess filew
# dual file includes for PHP compression
php_value  auto_prepend_file  /specify/full/path/to/gzip_start.php
php_value  auto_append_file   /specify/full/path/to/gzip_stop.php

Here's the Gzip section of my .htaccess file:

# ----------------------------------------------------------------------
# Gzip compression
# ----------------------------------------------------------------------

<IfModule mod_deflate.c>

# Force deflate for mangled headers developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/
<IfModule mod_setenvif.c>
  <IfModule mod_headers.c>
    SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s,?\s(gzip|deflate)?|X{4,13}|~{4,13}|-{4,13})$ HAVE_Accept-Encoding
    RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
  </IfModule>
</IfModule>

# HTML, TXT, CSS, JavaScript, JSON, XML, HTC:
<IfModule filter_module>
  FilterDeclare   COMPRESS
  FilterProvider  COMPRESS  DEFLATE resp=Content-Type /text/(html|css|javascript|plain|x(ml|-component))/
  FilterProvider  COMPRESS  DEFLATE resp=Content-Type /application/(javascript|json|xml|x-javascript)/
  FilterChain     COMPRESS
  FilterProtocol  COMPRESS  change=yes;byteranges=no
</IfModule>

<IfModule !mod_filter.c>
  # Legacy versions of Apache
  AddOutputFilterByType DEFLATE text/text text/html text/plain text/css application/json
  AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript 
  AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
</IfModule>

# Webfonts and SVG:
  <FilesMatch "\.(ttf|otf|eot|svg|php)$" >
    SetOutputFilter DEFLATE
  </FilesMatch>
</IfModule>
2
if you have a hundred plus pages in your project then perhaps you need to rethink your design pattern - Lawrence Cherone
What is the Content-Type the server send when you access the php files? - Gerben
@Gerben Excellent question. Content-Type:text/html; charset=UTF-8 - Micah
Did you resolve this? Have you checked the values of zlib.output_compression? - MrWhite

2 Answers

0
votes

Edit Your .htaccess File like This

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

# Or, compress certain file types by extension:

&ltfiles *.html &gt
SetOutputFilter DEFLATE
 &lt/files&gt

&ltfiles *.css&gt
SetOutputFilter DEFLATE
 &lt/files&gt

&ltfiles *.js &gt
SetOutputFilter DEFLATE
 &lt/files&gt

&ltfiles *.img &gt
SetOutputFilter DEFLATE
 &lt/files&gt
0
votes

If you have views with .php extension. You will have to add this to .htaccess file

<files *.php >
SetOutputFilter DEFLATE
 </files>