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

[Debug] Check headers sent before sending PHP response #10523

Closed
wants to merge 1 commit into from

Conversation

Projects
None yet
4 participants
@GromNaN
Copy link
Contributor

commented Mar 24, 2014

If the response contents has been sent before an error occurs, PHP triggers the warning "Cannot modify header information - headers already sent".

This change ensure that the useful error message is echoed, while it's impossible to change the HTTP status code and headers.

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR n/a
header(sprintf('HTTP/1.0 %s', $exception->getStatusCode()));
foreach ($exception->getHeaders() as $name => $value) {
header($name.': '.$value, false);
if (false === headers_sent()) {

This comment has been minimized.

Copy link
@stof

stof Mar 24, 2014

Member

please use !header_sent() here

[Debug] Check headers sent before sending PHP response
If the response contents has been sent before an error occurs, PHP
triggers the warning "Cannot modify header information - headers already sent"

This change ensure that the error message is echoed, while it's impossible
to change the HTTP status code and headers.
@staabm

This comment has been minimized.

Copy link
Contributor

commented Mar 25, 2014

Why is the content already sent over the wire?

The occurred exception in this scenario won't lead to a non http-200 status which is a problem itself, no?

@stof

This comment has been minimized.

Copy link
Member

commented Mar 25, 2014

@staabm if the header are already sent with a 200 status code, there is simply no way to send a different status code (even without this change). This fix means you will see the error message instead of seeing the PHP warning about headers being sent

@staabm

This comment has been minimized.

Copy link
Contributor

commented Mar 25, 2014

so should we log a message on warning/debug level which makes the dev aware of this issue...
already sent content is a error in itself, isn't it`?

@GromNaN

This comment has been minimized.

Copy link
Contributor Author

commented Mar 25, 2014

@staabm This is done like this in Response::sendHeaders().

I'm not sure that we need a log for that. The developer need to focus on the actual problem, not on this resulting effect.

@GromNaN GromNaN added the Debug label Mar 26, 2014

fabpot added a commit that referenced this pull request Mar 26, 2014

bug #10523 [Debug] Check headers sent before sending PHP response (Gr…
…omNaN)

This PR was merged into the 2.3 branch.

Discussion
----------

[Debug] Check headers sent before sending PHP response

If the response contents has been sent before an error occurs, PHP triggers the warning "Cannot modify header information - headers already sent".

This change ensure that the useful error message is echoed, while it's impossible to change the HTTP status code and headers.

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Commits
-------

97591c1 Check headers sent before sending PHP response

@fabpot fabpot closed this Mar 26, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.