Cannot use output buffering in output buffering display handlers
Asked Answered
D

4

17

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
Disturb answered 26/11, 2015 at 10:22 Comment(11)
Whats the memory limit in the used php.ini, i think if you set it to a higher value it will work.Godsend
The memory_limit in php.ini? It's 1024M at the momentDisturb
That should be enough! Is it a custom site or wordpress?Godsend
Do you output the buffer in the ob_start callback?Tropo
Can you provide us with a little more information of where and how you are using the ob_start?Godsend
We replace every {{TEXTID}} string in the output to the appropriate textDisturb
can you add that bit of code to the question so we can see it? like Alex said do you output the buffer in the callback, or are you actually using a callback for the ob_startGodsend
I use a callback functionDisturb
please copy all the code thats causing the error, now we're missing a lot of information that we can use to fix the error, replace sensitive data with ******, there's no context for us to work with. you're saying ob_start causes the bug, but i can tell you that's not the problem, it's the callback function that has the error.Godsend
maybe interesting? ob_get_status — Get status of output buffersCoax
can u post exact log enteriesPolyhydric
S
3

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.

Schrader answered 8/12, 2015 at 0:19 Comment(0)
P
11

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();
Patentor answered 8/12, 2015 at 19:35 Comment(0)
D
8

Even though this is an old question, I just wanted to add that the same error occurs when the system runs out of memory while buffering.

If this is the case, the error mentioned in this topic will always be followed by an Allowed memory size of xxx bytes exhausted error.

Dextroglucose answered 13/3, 2022 at 22:8 Comment(0)
S
3

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.

Schrader answered 8/12, 2015 at 0:19 Comment(0)
I
-1

maybe this sample code can help you:

ob_start();
echo "test";
$content = ob_get_contents();
ob_end_clean();
var_dump($content);
Iolanthe answered 8/12, 2015 at 15:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.