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.
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.