Home arrow PHP arrow Page 8 - Output Buffering With PHP

Zip Zap Zoom - PHP

Hate those ugly error messages that PHP generates when it encounters an error in your scripts? Can't stand half-constructed Web pages? Well, maybe you should take a look at PHP's output control functions, which offer an interesting and powerful solution to the problem.

  1. Output Buffering With PHP
  2. The Matrix Awaits
  3. Start Me Up
  4. Melting Down
  5. Today's Forecast
  6. Making It Simpler
  7. The Real World
  8. Zip Zap Zoom
  9. Endgame
By: Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 69
April 30, 2002

print this article


With everyone and their grandma now online, Web site are making an effort to provide users with more and better content. However, with bandwidth and download time still issues, it's essential that Web developers ensure this content is made available to the end-user as quickly as possible.

PHP's output control API offers an interesting solution to the problem, making it possible to compress the output sent to the client on-the-fly to reduce download time. Of course, the client needs to support this - but if it does, using this feature can make your Web site more efficient and your users happier.

Here's an example:

<?phpob_start("ob_gzhandler");?><html><head></head><body><!-- content goes here --><!-- content goes here --></html></body><?phpob_end_flush();?>
In this case, I've specified a callback function for the output buffer. For once, this callback is not a user-defined handler; rather, it is a PHP function named ob_gzhandler() whose sole purpose is to determine whether the client can accept compressed data (via the Content-Encoding header). If it can, ob_gzhandler() compresses the contents of the output buffer and sends it to the client, which then decodes and renders it; if not, the data is sent as is, in uncompressed form.

>>> More PHP Articles          >>> More By Harish Kamath, (c) Melonfire

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: