Forum Moderators: coopster

Message Too Old, No Replies

ob_end_flush;

Is it really neccessary?

         

lZakl

7:08 pm on Jun 6, 2005 (gmt 0)

10+ Year Member



Say I have the following code on the inside of one of my pages to check for a seesion...

<?php
session_start();
ob_start();
$page_title = "Some Other Page";

// Authorization check
if (!isset($_SESSION['USERPASS']))
{
$redirect_url = "index.php";
header("Location: $redirect_url");
}
ob_end_flush;
?>

I have read that the ob_end_flush; isn't needed: That PHP.ini automatically executes it if a ob_start() was called. Is this true? If so, can including it in the script anyway cause problems? I was just curious. Thank's in advance for you opinion! :0)

-- Zak

mcibor

8:33 pm on Jun 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What is ob_start()? It's a function that stores all errors in a buffer (doesn't display them).

So what will happen if you ob_end_flush()? You will diplay all the data stored in that buffer.

So to clean the buffer and write the data out use ob_end_flush() and if you don't want to show any errors use ob_end_clean()

More about it is in [php.net...]

Best regards
Michal Cibor

lZakl

9:30 pm on Jun 6, 2005 (gmt 0)

10+ Year Member



I am aware of what the commands are for the buffer, and what the buffer does. What my question is: Is the buffer flushed automatically at any point. Some comments on the PHP site suggest that one may not have to do it manually, and that PHP may do it automatically.

[us4.php.net...]

This is more of a curiousity issue than functionality ...

-- Zak

mcibor

10:00 pm on Jun 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's not explained there, but I think that the buffer is emptied when the script finishes to work. Otherwise such a small mistake would be able to cover whole disk storage just for buffering the errors.

Sorry for the function explanation
Michal

mincklerstraat

7:23 pm on Jun 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I do believe PHP will output the contents of the buffer if you just use ob_start(); and don't do an ob_end_clean(); . I always get the contents with ob_get_contents() and output it explicitly, just so I can see what my script is doing where when I come back to it.