Skip to content

Improved Bug Report for "header already sent" warning #10721

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

Closed
ianwhiteley opened this issue Feb 27, 2023 · 0 comments · Fixed by #10736
Closed

Improved Bug Report for "header already sent" warning #10721

ianwhiteley opened this issue Feb 27, 2023 · 0 comments · Fixed by #10736

Comments

@ianwhiteley
Copy link

WARNING RECEIVED
PHP Warning: session_start(): Cannot start session when headers already sent in /filepath on line xx

CURRENT SCENARIO & ISSUE
This warning gives the line number xx of the session_start(). It does not tell you WHAT triggered the sending of headers before this point was reached, and where that point is.

REQUESTED IMPROVEMENT
Add the file / line number for WHEN the last headers were previously sent - as this can be very difficult to pinpoint.

@damianwadley damianwadley transferred this issue from php/doc-en Feb 27, 2023
NattyNarwhal added a commit to NattyNarwhal/php-src that referenced this issue Feb 28, 2023
Duplicated session starts can be annoying to debug. The error that
occurs when a session is already active doesn't tell you where it
was initialized, so figuring out the callsite involves manual
debugging to find it out.

This keeps track of the call site of session_start as a request
global, and frees at the end of the request. It should make it
easier to find these instances for PHP users.

The resulting message can look like:
Notice: session_start(): Ignoring session_start() because a session is already active (started from /home/calvin/src/php-src/inc.php on line 4) in /home/calvin/src/php-src/index.php on line 9

Fixes phpGH-10721
Girgias pushed a commit that referenced this issue Mar 28, 2023
* Note where a session was already started

Duplicated session starts can be annoying to debug. The error that
occurs when a session is already active doesn't tell you where it
was initialized, so figuring out the callsite involves manual
debugging to find it out.

This keeps track of the call site of session_start as a request
global, and frees at the end of the request. It should make it
easier to find these instances for PHP users.

The resulting message can look like:
Notice: session_start(): Ignoring session_start() because a session is already active (started from /home/calvin/src/php-src/inc.php on line 4) in /home/calvin/src/php-src/index.php on line 9

Fixes GH-10721

* Convert to using zend_string for session start location

* Fix leak with session start callsite filename

If this was already initialized, we'd forget it. Have shared free
between session_start and RSHUTDOWN.

* For sessions that are automatically started, note that

Easy to forget that you have this set, in which case, session start
is done at RINIT outside of user code. Because this config option
can't change at runtime, we can check for it and make the error
more specific if that's the case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants