Output Buffering With PHP - Making It Simpler
(Page 6 of 9 )
In case you're wondering, it isn't really necessary for you to call ob_start() and ob_end_flush() at the beginning and end of every script if you don't want to. Once you make the decision to use output buffering in your scripts, you'll find it quite annoying to include two extra lines of code at the top and bottom of each and every script in your application.
Well, there's a simple solution - you can have PHP automatically transfer all script output to an output buffer by explicitly switching buffering on for *all* scripts , either via a configuration directive in the "php.ini" configuration file, or via a call to ini_set().
output_buffering = On
This is sometimes referred to as implicit buffering, since it's handled automatically by the PHP engine.
If you'd like to restrict the output buffer to a specific size, you can do so by specifying the size as a numeric value to the configuration drirective above.
It's important to keep in mind, though, that while implicit buffering is a fairly cool thing, there are a couple of caveats which come with it. First, implicit output buffering adds to the work PHP has to do when processing a script, which could end up degrading performance. Second, since all the output of the script is stored in a separate buffer, debugging script errors becomes far more complicated.
Next: The Real World >>
More PHP Articles
More By Harish Kamath, (c) Melonfire