Hello all,

     I just want to know what is the need of ob_start in php it stored the output in buffer.

    So where we have to use ob_start in real application. why we need to store the ouput in buffer?


   can you give me basic example when it is useful

Thanks and regards,
--Amit Patel

    As stated in the manual in the introduction to the output buffering section:

    The Output Control functions allow you to control when output is sent from the script. This can be useful in several different situations, especially if you need to send headers to the browser after your script has began outputting data. The Output Control functions do not affect headers sent using header() or setcookie(), only functions such as echo() and data between blocks of PHP code.

    Or, how I might paraphrase that:
    [indent]The Output Control functions allow you to make your script still work when you've done a poor job of separating the control layer from the view layer of your application. 😉[/indent]
    PS: Another possible use is for compression of output via the ob_gzhandler() function, but really this is probably better done via the zlib.output_compression setting in your PHP configuration.

      computerzworld wrote:

      You can get basic idea for the ob_start from here

      That does not actually say what it is useful for, and frankly I cannot think of a case where it is really useful, assuming that you structure your script properly.

        Write a Reply...