SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru SharifTK's Avatar
    Join Date
    Jan 2004
    Location
    New York, NY
    Posts
    621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Output Buffering Question

    I've used OB before in my scripts but I don't think it was ever used properly, or at least not the way its meant to be. Tell me how efficient this script would be:
    PHP Code:
    ob_start();
    //echo bunch of content, say 50 lines of content
    ob_end_flush();
    ob_end_clean(); 
    In a tutorial I read if I were to use ob_start('gz_handler'), it would save bandwith but increase CPU usage, is that right?
    SK

  2. #2
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by SharifTK

    In a tutorial I read if I were to use ob_start('gz_handler'), it would save bandwith but increase CPU usage, is that right?
    Yes, the extra CPU usage is because the file is being compressed. And that takes more work.
    But it saves bandwith since the files are smaller.



    --ed

  3. #3
    SitePoint Member R45's Avatar
    Join Date
    Mar 2004
    Location
    Trinidad and Tobago
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    CPU usage is increased on both sides, because the browser has to decompress the data. Usually, the bandwidth saved from using Gzip is substantial.

  4. #4
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might be able to offset the CPU time by installing an accelerator:

    http://turck-mmcache.sourceforge.net/
    My name is Steve, and I'm a super-villian.

  5. #5
    SitePoint Evangelist Daijoubu's Avatar
    Join Date
    Oct 2002
    Location
    Canada QC
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    At level 1 (minimum) it's about 70% saving
    Speed & scalability in mind...
    If you find my reply helpful, fell free to give me a point

  6. #6
    SitePoint Guru SharifTK's Avatar
    Join Date
    Jan 2004
    Location
    New York, NY
    Posts
    621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I use ob_start('ob_gzhandler') to "compress" pages, which equals less load time, will it reduce quality of images, and is the time or cpu load noticable.
    SK

  7. #7
    SitePoint Guru SharifTK's Avatar
    Join Date
    Jan 2004
    Location
    New York, NY
    Posts
    621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, the proper way of doing OB is this correct?:

    PHP Code:
    ob_start();
    //content
    ob_end_flush(); 
    And when is OB really necassary?
    SK

  8. #8
    SitePoint Evangelist Daijoubu's Avatar
    Join Date
    Oct 2002
    Location
    Canada QC
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SharifTK
    If I use ob_start('ob_gzhandler') to "compress" pages, which equals less load time, will it reduce quality of images, and is the time or cpu load noticable.
    No, GZIP only compress the text (HTML), the rest is unaffected
    If you have set the compression level to it lowest, there shouldn't be any impact on the load

    Usually, you won't need to explicitly flush it since PHP would do it at the end of your script execution

    Buffering should be always enabled for best performance

    ob_start();
    // bunch of echo

    Is faster than:
    // Only a bunch of echo()
    or:
    // Bunch of concatenations $to_echo .= 'Hello World';
    // then echo $to_echo;
    Last edited by Daijoubu; Mar 15, 2004 at 20:00. Reason: Spelling
    Speed & scalability in mind...
    If you find my reply helpful, fell free to give me a point


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •