After update to 2.0.14.1
in end of all page of my project i see this:
An Error occurred while handling another error:
yii\web\HeadersAlreadySentException: Headers already sent in C:\xampp\htdocs\myproject\vendor\yiisoft\yii2\widgets\ContentDecorator.php on line 79. in C:\xampp\htdocs\myproject\vendor\yiisoft\yii2\web\Response.php:366
Stack trace:
Previous exception:
yii\web\HeadersAlreadySentException: Headers already sent in C:\xampp\htdocs\myproject\vendor\yiisoft\yii2\widgets\ContentDecorator.php on line 79. in C:\xampp\htdocs\myproject\vendor\yiisoft\yii2\web\Response.php:366
Stack trace:
and also in debug panel have one error log
with category:
yii\web\HeadersAlreadySentException
and message:
yii\web\HeadersAlreadySentException: Headers already sent in C:\xampp\htdocs\myproject\vendor\yiisoft\yii2\widgets\ContentDecorator.php on line 79. in C:\xampp\htdocs\myproject\vendor\yiisoft\yii2\web\Response.php:366 Stack trace: #0 C:\xampp\htdocs\myproject\vendor\yiisoft\yii2\web\Response.php(339): yii\web\Response->sendHeaders() #1 C:\xampp\htdocs\myproject\vendor\yiisoft\yii2\baseApplication.php(392): yii\web\Response->send() #2 C:\xampp\htdocs\myproject\frontend\web\index.php(17): yii\baseApplication->run() #3 {main}
should I do any changes in my project? or this is a bug in framework?
seems related to https://github.com/yiisoft/yii2/issues/15782
Ok I also see http://www.yiiframework.com/news/165/yii-2-0-14-is-released/ Error handling section
But How i can found where i set header by this error trace!
Use headers_sent()
function. See https://stackoverflow.com/a/15844021/3584248 for details
that's right but in Response in framework headers_sent() used and only return probelm is in
view.php of framework files and line 181!
ok if i set a header in my project or other extentions i installed how found that?
Maybe step-by-step debug?
it is not better to change in the error logger to have better log !??
when i comment
// if (headers_sent($file, $line)) {
// throw new HeadersAlreadySentException($file, $line);
// }
in response.php of framework
see this error:
Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\myproject\vendor\yiisoft\yii2\web\View.php:181)
I am trying to find it for 5 hours step by step commenting all component bootsrap and all thing in view.
but i could not find it yet.
@hooman-pro Are you echo
ing content somewhere in your application instead of return
ing it in the controller action?
@schmunk42
No, I did not.
But this error only occurred in frontend , backend has not this error however!
One thing is amazing is in frontend actions if i write $this->render(...) or return $this->render(...) both of them work correctly (with this error)! but in backend $this->render(...) dont show any thing!
I guess the problem is related to this.
Maybe you have a file in you project with space or newline before opening PHP tag (<?php
) or after closing php tag (?>
). This will also lead to Headers Already Sent
exceptions
See https://github.com/yiisoft/yii2/issues/15782#issuecomment-368553054 for a quick workaround (enabling output buffering)
Finally problem found. thanks all
I changed
output_buffering=4096
to
output_buffering=On
in php.ini
By changing output_buffering to On in the server, Can this makes problem in future?
The reason for this problem was only one line I forgot to put
beginPage() ?>
in first of my layout before
And now with out needing change output_buffering it work currectlly without any error
simply do
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
\Yii::$app->response->data = $data;
In my case problem was when some controller makes "echo".
My project always echo api result (and not return), how can I fix one for all api or I must fix one by one?
Using global find-replace?
Most helpful comment
The reason for this problem was only one line I forgot to put
beginPage() ?>
in first of my layout before
And now with out needing change output_buffering it work currectlly without any error