Utilizing GZip with WordPress, Finally a Fast Blog…

The first half of this arti­cle will be taken directly from our pre­vi­ous post, as the need for a sin­gle default php.ini is nec­es­sary to con­fig­ure gzip. If read­ing our Magento post is what brought you to the site, and you’ve already con­fig­ured your default php.ini, than skip to the .htac­cess por­tion of the post. Oth­er­wise, were off…

The major­ity of peo­ple read­ing this arti­cle with be on a shared host­ing plat­form. So we’ll be explain­ing the steps in those terms. If you don’t already know whether gzip is avail­able on your server, copy the fol­low­ing code to an html edi­tor, or a text edi­tor, and save it as test.php.

1
2
3
<?php
phpinfo();
?>

Load the file to your server, and nav­i­gate to it with you web browser. If you see gzip any­where on the info page, your in luck. Remem­ber to remove this file before mov­ing on, as it does pose a secu­rity threat if left on the server.

Next you need to log into you host­ing account and access your cpanel. Keep in mind that most good host­ing com­pa­nies will help you with all of this, so never be ashamed to for help.

The first thing we need to do is install a Sin­gle Default ini. Log into your cpanel, and choose php con­fig, under your soft­wares / ser­vices panel. , and always remem­ber to backup your files and data­bases fre­quently. Make sure your sites are all run­ning PHP5, and choose (Sin­gle php.ini) Choose save, and scroll down. To com­plete the install. and then select Ion­Cube and Source­Guardin and click “Install php.ini Mas­ter File”. This man­u­ally directs sys­tem resources to the new loca­tion of your sin­gle php.ini file. Call your host if you need help. Down­load the file from the root direc­tory of your server ( php.ini.default ) Next rename the file to php.ini and open it. Locate the mem­ory set­tings, Cur­rently located on line 227. Your loca­tion may vary.

227
228
229
230
231
232
233
;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;
 
max_execution_time = 30     ; Maximum execution time of each script, in seconds
max_input_time = 60	; Maximum amount of time each script may spend parsing request data
memory_limit = 32M      ; Maximum amount of memory a script may consume (32MB)

and change the default mem­ory from a whop­ping default of 32m to a min­i­mum of 64m in a busy envi­ron­ment, or prefer­ably to some­thing like 128m, or even 256m if run­ning a siz­able store on a stand alone server. Set­ting the ram even higher can lead to sys­tem insta­bil­i­ties, and inter­ven­tion by your sys­tem admins. With this default ini in place, you’ve now set a global mem­ory set­ting, across every folder on your server. This is a sure fire way to elim­i­nate freez­ing dur­ing check­out, and other ran­dom Magento weirdness.

Another option while here would be to increase exe­cu­tion time. While not nec­es­sary, espe­cially with our now increased Ram, our sug­ges­tion would be noth­ing more than 120 sec­onds. If you’ve got a script run­ning longer than a minute or two, there’s prob­a­bly some­thing wrong, and a forced stop is in order.

Now that we’ve got more mem­ory, and and in turn improve­ment in sta­bil­ity, and reli­a­bil­ity, lets really make this thing really boo­gie. With our default ini still open, search for ob_gzhandler This is also an area where you’ll see a men­tion of the use of either gzip or zlib, and never both. Dupli­cate the line con­tain­ing the fol­low­ing script. Cur­rently located on line 106. Your loca­tion may vary.
output_handler = ob_gzhandler

104
105
106
107
108
109
110
111
112
113
114
115
116
117
; Note: You cannot use both "mb_output_handler" with "ob_iconv_handler"
;       and you cannot use both "ob_gzhandler" and "zlib.output_compression". 
output_handler = ob_gzhandler
 
; Transparent output compression using the zlib library
; Valid values for this option are 'off', 'on', or a specific buffer size
; to be used for compression (default is 4KB)
; Note: Resulting chunk size may vary due to nature of compression. PHP 
;       outputs chunks that are few hundreds bytes each as a result of 
;       compression. If you prefer a larger chunk size for better 
;       performance, enable output_buffering in addition.
; Note: You need to use zlib.output_handler instead of the standard
;       output_handler, or otherwise the output will be corrupted.
zlib.output_compression = Off

Notice zlib is either com­mented out, or off. Be sure it stays this way. With your PHP.ini now fin­ished, reload it to the root of your server. This one file pro­vides the sin­gle largest per­for­mance and sta­bil­ity improve­ment you will find with Magento.

Now we talk about Word­Press. Retrieve your .htac­cess file from the root of your Word­Press install, and copy paste the script below to theend of your .htac­cess file. Dupli­cate the set­tings you see below. While we’re on the sub­ject of mem­ory speed, an arti­cle we wrote a few moths back may also inter­est you. In the arti­cle titled Word­Press, Fatal error: Allowed mem­ory size of 33554432 bytes exhausted We describe how to increase the mem­ory allo­cated to wordpress.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<IfModule mod_gzip.c>
    mod_gzip_on                                     Yes
    mod_gzip_can_negotiate                          Yes
    mod_gzip_static_suffix                          .gz
    AddEncoding                     gzip            .gz
    mod_gzip_update_static                          No
    mod_gzip_command_version                        '/mod_gzip_status'
    mod_gzip_keep_workfiles                         No
    mod_gzip_minimum_file_size                      512
    mod_gzip_maximum_file_size                      1048576
    mod_gzip_maximum_inmem_size                     60000
    mod_gzip_min_http                               1000
    mod_gzip_handle_methods                         GET POST
    mod_gzip_item_include           mime            ^text/.*
    mod_gzip_item_include           mime            ^httpd/unix-directory$
    mod_gzip_item_include           file            \.shtml$
    mod_gzip_item_include           file            \.html$
    mod_gzip_item_include           mime            ^application/x-javascript$
    mod_gzip_item_include           mime            ^application/javascript$
    mod_gzip_item_include           file            \.js$
    mod_gzip_item_include           file            \.css$
    mod_gzip_item_include           mime            ^application/x-httpd-php$
    mod_gzip_item_include           file            \.php$
    mod_gzip_item_include           handler         ^cgi-script$
    mod_gzip_dechunk                                Yes
    mod_gzip_item_include           mime            ^image/.$
    mod_gzip_item_include           mime            ^image/
    mod_gzip_item_include           rspheader       Content-Type:image/*
</IfModule>

The very blog you’re read­ing from now is even uti­liz­ing this fix. Be aware, if you have a script inten­sive, or pho­tog­ra­phy site, you may want to exclude that con­tent from gzip. This is easy enough to do by sim­ply replac­ing the word include with exclude. Tough fix huh? Hope­fully we were able to help you, let use know with a comment.

And if you’d like to see the results first hand, sim­ply copy & paste you’re web­sites URL to any­one of the fol­low­ing links. Thanks for stop­ping by.

GZip Test­ing Sites

  1. GZip Dis­crim­i­na­tion Test
  2. Whatsmyip


Was this article helpful? Here's a few related articles which may also interest you.

Related Posts:


Leave a Comment