why do I need to end my ob_start()?
Asked Answered
W

3

9

The php documentation suggests that I should end each ob_start() with an ob_end_flush(). I am using one on each page of a site, just to allow me to use firephp log methods anywhere in the app.

the app works fine, but I wonder if there is anything I don't know that might be detrimental.

Wivina answered 8/11, 2010 at 11:36 Comment(0)
R
9

I think the reason for this suggestion is, that PHP flushes your output buffer implicitly when not using one of the ob_end_* functions. While not an error, this can cause problems when not expecting it. The PHP-docs try to protect you from these kind of problems. If you are aware of the implicit flush, it is probably not an issue.

Radicle answered 8/11, 2010 at 11:43 Comment(0)
W
0

You can use Output Buffering as

<?php
ob_start();
echo "Some text you want to echo on page!!";
header("Location:somepage.php");
ob_end_flush();
?>

The problem is that we cannot send the header after we start sending the output. To solve this we buffer the output. The function ob_start turns output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer. So the echo output will be buffered. Next we send the header without any problem as we've not yet spit out any output. Finally we call ob_end_flush to flush the internal buffer contents and to stop output buffering.

Womanhater answered 8/11, 2010 at 11:45 Comment(0)
M
0

if there is loops, for example, some one can start buffering. And calls your function. When he tries to ob_end_flush code gathers your contents.

Mohammadmohammed answered 8/11, 2010 at 11:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.