Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yii\web\HeadersAlreadySentException: Headers already sent. #2

Open
ChaDmiS opened this issue Jul 14, 2021 · 2 comments
Open

yii\web\HeadersAlreadySentException: Headers already sent. #2

ChaDmiS opened this issue Jul 14, 2021 · 2 comments

Comments

@ChaDmiS
Copy link

ChaDmiS commented Jul 14, 2021

If you decide to use this solution, as I did, then you may encounter an error resending headers yii\web\HeadersAlreadySentException: Headers already sent.

The thing is that licson/libSSE-php itself sends headers via Symfony StreamedResponse https://github.com/licson/libSSE-php/blob/master/src/SSE.php#L266, without affecting Yii in any way.

This solution does not take this into account.

Yii sends headers here https://github.com/yiisoft/yii2/blob/master/framework/web/Response.php#L346

So I just told Yii that the response has already been sent, something like this:

Yii::$app->response->isSent = true;

Full example:

Yii::$app->response->isSent = true;
$sse = Yii::$app->sse;
$sse->addEventListener ('message', new MessageEventHandler ());
$sse->start();

The solution, of course, is straightforward, but it works :)

@raezon
Copy link

raezon commented Jul 15, 2021

it does work

@donal56
Copy link

donal56 commented Oct 28, 2021

Thanks, it worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants