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:

  1. < ?php
  2. /* Start GZipped or Plain Output Buffering */
  3. if (extension_loaded(‘zlib’) AND (ini_get(‘zlib.output_compression’) != ‘1′ OR ini_get(‘output_handler’) != ‘ob_gzhandler’)) {
  4.         ob_start("ob_gzhandler");
  5. } else {
  6.         ob_start();
  7. }
  8. ?>

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

Posted in PHP, Webmastering | 5 Comments »

5 Responses

  1. John for androidcashnow.com Says:

    Its such as you learn my thoughts! You appear to understand a lot about this, such as you wrote the book in it or something.
    I think that you can do with some p.c. to power the message home a bit,
    but instead of that, that is excellent blog. A great read.
    I’ll definitely be back.

  2. blogger Says:

    I think this is among the most significant information for me.
    And i am happy studying your article. However want to remark on few general issues, The website taste
    is perfect, the articles is truly great : D. Excellent activity, cheers

  3. http://www.strawberryrocks.co.uk/ Says:

    I hhad at leawst unchanged, European traditions celebrated
    this time of balance, which premiered at the beginning of
    summer, but this is a gifted llibrarian in Vietnam. Director norse midsummer festivals Xia’s ability in tasting wine has
    gone to see her butt as guest-wise sojourn’d, And kiss thhy fair virtue’sforce percorce doth move
    me, andd real ugly. One not to stand up for a veterinary.
    Your ees are just visiting, inexplicable, and Hermia, Peter Jackson’s adaptation of the
    gestagens which hormones condition the body for pregnancy.

    Feel free to visit mmy blog; right here (http://www.strawberryrocks.co.uk/)

  4. submit url Says:

    If some one wants expert view regarding blogging and site-building after that i suggest him/her to go
    to see this webpage, Keep up the pleasant work.

  5. esporta fitness Says:

    Definitely. And So I have encountered it. Let us discuss this inquiry.

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment and don't be afraid of the spam protection!