PHP
  Home arrow PHP arrow Page 4 - An Object-based Approach to HTTP Compression in PHP
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

An Object-based Approach to HTTP Compression in PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 6
    2006-04-17


    Table of Contents:
  • An Object-based Approach to HTTP Compression in PHP
  • Object-based "Gzip" compression: creating a data compressor PHP class
  • Setting up a concrete example: putting the "DataCompressor" class to work
  • Explaining the example

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    An Object-based Approach to HTTP Compression in PHP - Explaining the example
    ( Page 4 of 4 )

    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
     

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek