Maximize PHP performance with Apache compression

Does your site run as quickly as it could? It’s worth your time to find out. Faster web sites sell more products, improve user satisfaction, and even rank higher in Google searches.

Note: This tip was written for IBM i but could be adapted for other platforms as well.

Compression adds speed

IBM’s Apache web server provides a way to speed up your pages. You can compress PHP output, javascript, style sheets, and other text-based content. The compressed output will automatically be decompressed and interpreted properly by all modern web browsers. My tests show a speed improvement of 10-50% from this easy technique.

How to enable compression in 3 steps

1. Edit your Apache configuration file, located at /www/myserver/conf/httpd.conf (replace myserver with your instance name. This is a simple text file, so you may choose from several editors: IBM’s HTTP Server Admin GUI at port 2001 (if *ADMIN is started), the WRKLNK/EDTF command, or your favorite text editor.

2. Add the following two directives to the httpd.conf’s main section:

3. Restart Apache via the HTTP Server Admin page or STRTCPSVR SERVER(*HTTP) RESTART(*HTTP) HTTPSVR(MYSERVER)

Measure the improvement

I ran before-and-after tests using a sample script included with Zend Server for IBM i: http://your-server:10088/Samples/SQL_access/DB2_SQL_example.php.

Before compression: 31kb, loaded in 250ms (milliseconds). See the Firebug report below (Firebug is an optional add-on for Firefox and is not required.)

Zend Server output without compression

Without compression, this page was 31kb and loaded in 250ms

After compression: 4.4kb; loaded in 109ms. That’s only 14% of the size and 50% of the time! See the screen shot below.

after compression: only 4.4kb and loaded in 109ms

after compression: only 4.4kb and loaded in 109ms

I highly recommend that you give output compression a try. Your HTTP Server for IBM i pages will fly!

For more information on browser output compression, see: http://httpd.apache.org/docs/2.0/mod/mod_deflate.html

5 replies
  1. Alan Seiden
    Alan Seiden says:

    Keith,

    Compressed content gets decompressed when it reaches the user’s web browser. The browser controls this process, first sending a “gzip” header that asks the server to use compression, if possible, and then decompressing the content that’s received from the server.

    As for your future Citrix environment (where web browsers will run in virtual machines on centralized servers in your data center), the benefits of compression will still be there, but you will probably notice less of an improvement than than if your users connected with browsers outside the network.

    With compression, the improvements in speed always depend on these factors:
    1. the size and compression ratio of your content (how large the files are to start with and how small they become when compressed)
    2. network traffic and speed

    Larger files and slower networks (and internet connections) will benefit the most from compression. Smaller files and faster networks reduce the benefits.

    Compression/decompression does require CPU on the server and browser, so if the files are small, and served over a fast intranet, the trade-off might not be worth it.

    The only way to know for sure is to try with your actual website and network. I hope you’ll give the technique a try and, perhaps, add a comment here to tell us how it went.

    Alan

    Reply
  2. Keith Livingood
    Keith Livingood says:

    Alan,

    I have a question concerning your article on Apache compression. In the near future, we are going to a virtual desktop environment/Power 7.1 system i blade and I am wondering if this tip on Apache compression would still be beneficial.

    In today’s environment with Apache compression turned on for Zend Server, I understand that a php page would be compressed down and sent over the wire to the user’s desktop. Once it gets to the user’s desktop, does it decompress to present itself?

    In a Citrix environment, the creation of the page and the sending of the page would all take place in our data center……could we still gain time if we used the Apache compression? Any help would be appreciated.

    Keith

    Reply
  3. Scott Campbell
    Scott Campbell says:

    Alan,

    Thanks, I was looking at this with ZendCore but never got it working. I got results similar to you and appreciate the information on how you got it going.

    Scott

    Reply

Trackbacks & Pingbacks

  1. […] more: Alan Seiden's Information Technology » Maximize Zend Server PHP … No […]

  2. […] Pe?ny artyku? na: Alan Seiden's Information Technology » Maximize Zend Server PHP … […]

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.