Home arrow PHP arrow Page 4 - An Object-based Approach to HTTP Compression in PHP

Explaining the example - 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.

  1. An Object-based Approach to HTTP Compression in PHP
  2. Object-based "Gzip" compression: creating a data compressor PHP class
  3. Setting up a concrete example: putting the "DataCompressor" class to work
  4. Explaining the example
By: Alejandro Gervasio
Rating: starstarstarstarstar / 6
April 17, 2006

print this article



First, the script instantiates a new "DataCompressor" object, and secondly passes the sample PHP file that you just saw to the constructor. Since the source code of the "fetchCompressedData()" method will include this file after opening an output buffer, its whole dynamic output will be first "crunched" (that is, all new line characters will be removed) and finally compressed by the "Gzip" encoding algorithm.

Before the data is actually encoded, the script calls the "sendEncodingHeader()" method, in this way indicating to the browser that contents will be transmitted compressed over the network. At the end of the script execution, the data is transparently decoded by the browser, and finally displayed to the user.

As you can see, the whole data compression/decompression process is handled by the "DataCompressor" class in combination with the corresponding user agent, which means that using HTTP compression to make dynamic PHP pages load faster is quite easy to implement in several PHP scripts.

To wrap up

Unfortunately, that's all for the moment. Throughout this second part of the series, I demonstrated how to use HTTP compression in object-based development environments, by creating a data compressor class in PHP 5. As you learned in the article, this class utilizes a few simple methods for fetching incoming data, and then returns the contents properly compressed. Additionally, it allows you to send the corresponding HTTP header using a separate method, which makes the class even more flexible. Thus, if you feel inclined to extend its functionality, go ahead and develop a full-featured HTTP compression system.

In the last article of the series, I'll explain how to take advantage of HTTP compression within a PHP web page generator system, which uses objects to create dynamic web documents. Curious about how this will be achieved? You'll have to wait till the next part!

>>> More PHP Articles          >>> More By Alejandro Gervasio

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: