Properly disable output buffering.
We had some issues with a server which had output_buffering enabled via php.ini.
Debugging was made harder due to the fact that the Server creates an output buffer in its constructor, which is a side effect..
Since output_get_level will reliably tell us if output buffering is enabled, it would be nice to just throw an exception in that case:
public function __construct($verifyHeaders = true)
{
if (true === $verifyHeaders && true === headers_sent($file, $line)) {
throw new Exception(
'Headers already sent in %s at line %d, cannot send data ' .
'to client correctly.',
0,
[$file, $line]
);
}
if(ob_get_level() > 0) {
throw new Exception("Output buffering is active");
}
Alternatively output buffering could be disabled:
while (@ob_end_flush());
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
I think we have two options here:
- either throw a runtime exception if the output buffer is enabled,
- or tell in the documentation how to be sure that the output buffer is not enabled.
I am good with both.
Thoughts @hoaproject/hoackers and @SamMousa?
And thanks for using our library and for the clear bug report! Is it in an open source project?
@Hywan I prefer runtime exceptions, they are clearer.
The specific project I'm using it in now is not open source.
I'm up for creating a PR if you don't have the time :)
@SamMousa I have to admit that if you can create a PR, it would help us a lot :-). Thanks! Let's go for a runtime exception.