Output Buffering
December 4th, 2005 by
Quatrux
What I found interesting is that output buffering can be really handy and that using it for half of year I had no problems with it, I mean using ob_start() function with gz_handler here is an example, put it somewhere in top of your file:
-
< ?php
-
/* Start GZipped or Plain Output Buffering */
-
if (extension_loaded(‘zlib’) AND (ini_get(‘zlib.output_compression’) != ‘1′ OR ini_get(‘output_handler’) != ‘ob_gzhandler’)) {
-
} else {
-
}
-
?>
using it you can use header() function anywhere in the files even if you wrote echo or made some output, you can edit the output, just read about output buffering functions in the php manual – www.php.net/ob_gzhandler
because our html has so many the same tags it is just perfect for using gzip on it, it can compress up to 60% of your source, in this way you save bandwidth and time for the user to get the file and it works great because if the user browser can’t decode gzip it won’t be sent with gzip encoding, it saves time because apache does not need to use the resources of sending the file, but it uses a bit of resources to encode using gzip, all in all it is a thing which I found to late, but I am happy I found it, it opened me new possibilities.
Posted in PHP, Webmastering |
No Comments »
