Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot use output buffering in output buffering display handlers

I've reinstalled Apache, and switched from PHP 5.3 to 5.6. Everything works, except I get this error, when calling ob_start():

Cannot use output buffering in output buffering display handlers

I tried to enable output buffering in PHP, but I still get this error:

output_buffering = 4096
like image 922
Iter Ator Avatar asked Nov 26 '15 10:11

Iter Ator


People also ask

Why do we use Ob_start ()?

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 does buffering the output mean?

An output buffer is a location in memory or cache where data ready to be seen is held until the display device is ready.

What is output buffering in PHP?

Output Buffering is a method to tell the PHP engine to hold the output data before sending it to the browser.


2 Answers

You're trying to start a output buffer inside a buffer callback. If you use this code, it will generate that error. But if you remove the ob_start() from the callback function it's OK.

<?php
error_reporting(-1);

function callback($buffer){
    //you can't call ob_start here
    ob_start();
    return (str_replace("apples", "oranges", $buffer));
}

ob_start("callback");

?>
<html>
<body>
<p>It's like comparing apples to oranges.</p>
</body>
</html>
<?php
ob_end_flush();
like image 136
Antony Thompson Avatar answered Oct 11 '22 14:10

Antony Thompson


Probably you are using a buffering function in output buffering callback which isn't possible as mentioned in php ob_start output_callback documentation. If not it should be the output-handler you used, check your php.ini and try to set it's value to "none" if possible.

like image 39
mow Avatar answered Oct 11 '22 14:10

mow