Приглашаем посетить
Бианки (bianki.lit-info.ru)

Content Compression

Previous
Table of Contents
Next

Content Compression

HTTP 1.0 introduced the concept of content encodingsallowing a client to indicate to a server that it is able to handle content passed to it in certain encrypted forms. Compressing content renders the content smaller. This has two effects:

  • Bandwidth usage is decreased because the overall volume of transferred data is lowered. In many companies, bandwidth is the number-one recurring technology cost.

  • Network latency can be reduced because the smaller content can be fit into fewer network packets.

These benefits are offset by the CPU time necessary to perform the compression. In a real-world test of content compression (using the mod_gzip solution), I found that not only did I get a 30% reduction in the amount of bandwidth utilized, but I also got an overall performance benefit: approximately 10% more pages/second throughput than without content compression. Even if I had not gotten the overall performance increase, the cost savings of reducing bandwidth usage by 30% was amazing.

When a client browser makes a request, it sends headers that specify what type of browser it is and what features it supports. In these headers for the request, the browser sends notice of the content compression methods it accepts, like this:

Content-Encoding: gzip,deflate

There are a number of ways in which compression can be achieved. If PHP has been compiled with zlib support (the -enable-zlib option at compile time), the easiest way by far is to use the built-in gzip output handler. You can enable this feature by setting the php.ini parameter, like so:

zlib.output_compression On

When this option is set, the capabilities of the requesting browser are automatically determined through header inspection, and the content is compressed accordingly.

The single drawback to using PHP's output compression is that it gets applied only to pages generated with PHP. If your server serves only PHP pages, this is not a problem. Otherwise, you should consider using a third-party Apache module (such as mod_deflate or mod_gzip) for content compression.


Previous
Table of Contents
Next