Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

Properly disable output buffering. #22

Open
SamMousa opened this issue Jul 27, 2017 · 4 comments
Open

Properly disable output buffering. #22

SamMousa opened this issue Jul 27, 2017 · 4 comments

Comments

@SamMousa
Copy link

SamMousa commented Jul 27, 2017

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.

@Hywan
Copy link
Member

Hywan commented Aug 7, 2017

I think we have two options here:

  1. either throw a runtime exception if the output buffer is enabled,
  2. 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?

@Hywan
Copy link
Member

Hywan commented Aug 7, 2017

And thanks for using our library and for the clear bug report!
Is it in an open source project?

@SamMousa
Copy link
Author

SamMousa commented Aug 7, 2017

@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 :)

@Hywan
Copy link
Member

Hywan commented Aug 8, 2017

@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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants