I do not quite understand why this is necessary, but there is no reason not to publish the answer.
You can use the ob_start() and handle partial content. All you have to do is set ob_implicit_flush() right after initialization. Now usually a callback is a simple login function, but you can make it as complex as possible with:
class ob_callback { function __invoke($part, $end_flag_0x04) { return "+$part"; // or map to $stream->filter($in, $out, &$consumed, $closing) } function __destruct() { /* cleanup */ } } ob_start(new ob_callback, 2); ob_implicit_flush(TRUE);
I'm not sure what the stream will look like. But I think there is no other way to intercept standard PHP output. Note that an implicit flash will not work in the CLI.
source share