ob_start not executing callback
Asked Answered
D

1

7

I'm having issues with ob_start. Not sure what the deal is, but I've bubbled it down to the simplest possible test case... still to no avail. I would expect this code to output 'bar' to the stdout, but I'm getting nothing back, and no errors in my error log.

<?php
function gzhandler_ex($buffer, $mode)
{
    echo 'bar';
}

ob_start('gzhandler_ex');
echo 'foo';
ob_flush(); 

I've never seen this before, but I don't typically use callbacks like this.

Disharmonious answered 15/5, 2011 at 10:56 Comment(0)
S
9

Your handler function should return the content you want to output, not echo it.

function gzhandler_ex($buffer, $mode)
{
    return 'bar';
}

Also, the ob_flush() is unnecessary when called at the end of the script; it is implicit.

Scintillator answered 15/5, 2011 at 11:6 Comment(1)
Facepalm. Thanks much, I knew it had to be something so baseline.Disharmonious

© 2022 - 2024 — McMap. All rights reserved.