HomePHP An Object-based Approach to HTTP Compression in PHP
An Object-based Approach to HTTP Compression in PHP
Welcome to the second tutorial of the series “Using HTTP compression in PHP.” In three parts, this series demonstrates how to apply HTTP compression to parsed PHP pages, in order to reduce their overall download times, which results in faster delivery of dynamic content.
Over the first tutorial of this series, I developed some hands-on examples, aimed at illustrating how "Gzip" encoding can be used within PHP scripts to compress the output generated by dynamic PHP pages. After transferring the encoded data to the client, contents are uncompressed and finally displayed on the browser.
As you probably recall, the data encoding/decoding process that I just described was performed by a combination of the PHP built-in "gzencode()" function and some output buffering functions. These became extremely handy for storing temporarily the dynamic output of parsed PHP files and applying "Gzip" encoding on the respective data. Indeed, output buffering control can be used as a simple mechanism for implementing different kinds of post-processing on parsed data, such as caching (X)HTML output, or compressing dynamic pages, to name a few popular applications.
Now that the data compression methods shown in the previous article are hopefully familiar concepts to you, it's time to move toward the implementation of HTTP compression within object-oriented PHP applications, particularly, for obvious reasons, on those whose output include some sort of (X)HTML rendering process.
By the end of this article, you should have the appropriate knowledge for building a simple data compressor class, in addition to using HTTP compression for reducing the download time of object-generated web pages. I'm sure the subject is quite interesting to you, so let's dive into the topic together.