Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between ob_get_clean and ob_get_flush

They both seem to do the same thing: return the output buffer content to you and delete it aftewards.

Which one should I use?

like image 840
EEka Avatar asked Sep 11 '11 16:09

EEka


People also ask

What is Ob_get_clean?

The ob_get_clean() function returns the contents of the output buffer and then deletes the contents from the buffer.

What does Ob_start () function do?

The ob_start() function creates an output buffer. A callback function can be passed in to do processing on the contents of the buffer before it gets flushed from the buffer. Flags can be used to permit or restrict what the buffer is able to do.

What is output buffering in PHP?

Output buffering is a mechanism for controlling how much output data (excluding headers and cookies) PHP should keep internally before pushing that data to the client. If your application's output exceeds this setting, PHP will send that data in chunks of roughly the size you specify.


2 Answers

ob_get_clean() removes the buffer (without printing it), and returns its content.

ob_get_flush() prints the buffer, removes it, and returns its content.

Both function will terminate the buffer.

like image 62
Arnaud Le Blanc Avatar answered Oct 07 '22 17:10

Arnaud Le Blanc


ob_get_clean will just return the contents of the buffer and assign it to whatever variable you want it to, but it will not output anything.

ob_get_flush on the other hand, does everything that ob_get_clean does, but it also outputs the content.

like image 44
Shef Avatar answered Oct 07 '22 18:10

Shef