Results 1 to 7 of 7

Thread: ob_start() ??

Hybrid View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2004
    Posts
    24

    ob_start() ??

    Hi,

    I'm using ob_start() at the top of my script in order to be able to deal with setcookie() ... and at the bottom a wrote ob_flush() .

    Will this increase the performance and speed of the website or the opposite ??

    Do I need also to add ob_start( 'ob_gzhandler' ) ?

    Thanks

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: ob_start() ??

    Use of an output buffer does not increase the performance of your application. It actually adds an additional layer of processing to your application.

    Using an ouput buffer "to be able to" use setcookie() is unecessary and actually bad coding practice. With a well written script, you should never need to use an output buffer in order to use setcookie().

    However, controlling when and how your script produces output is sometimes necessary. For example, you may use an output buffer to collect output and discard it, replacing it for alternative output should a fatal error occur. The compression feature provided by the ob_gzhandler function is also another insance where an output buffer is required. The ob_gzhandler function collects the output and uses the gz algorithm to compress the content (where the client supports it) before sending it to the client. This can provide significant bandwidth savings.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2004
    Posts
    24

    Re: ob_start() ??

    Thanks ..

    I'm sure that it is not the best way of coding .. but most of the topics on how to solve setcookie() problem asked to use ob_start() to prevent any output before setcookie() ... do you have any idea how to work without ob_start() ??

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: ob_start() ??

    Yes, ensure use setcookie before you produce and output.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: ob_start() ??

    Output should be the very last thing your script does during its lifetime.

  6. #6
    New Member v!sualAd's Avatar
    Join Date
    Oct 2004
    Location
    Pasta factory
    Posts
    6

    Re: ob_start() ??

    Also, the output should only contain display logic. No processing
    I love pasta

  7. #7
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: ob_start() ??

    If you're mixing output and processing, imagine what would happen if an error occured halfway through the output/processing. You'd get half of the page out, and then an error, which, depending on the application, could end up looking like butt. It's frustrating, and I've run across it in several projects at work.

    It's always a good idea to do output after all processing.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

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



Click Here to Expand Forum to Full Width