Tell PHP the configured session lifetime while it will still listen - #718
Merged
Conversation
PHP refuses to change a session ini setting once a session is active, and the attempt to set session.gc_maxlifetime was made from initUserSession — by which point Context::initialize() had already started one. So it always failed silently, and PHP's own collector was left on whatever the platform default happened to be: free to delete a session file that the application still considered valid, logging people out of an installation configured for a longer session. Set it in initialize(), before the session is started, which is the only moment PHP accepts it. The branch it came from still resolves and stores this session's own timeout — that call had a side effect worth keeping, and for a session this new nothing else has made it. The test asserts the value PHP ends up with, and fails without the change. It also closes the session the harness starts in setUp, so it asks what a real request asks: was this in place before the session existed?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
Inittried to setsession.gc_maxlifetimefrominitUserSession()— butContext::initialize()has already started the session by then, and PHP refuses to change a session ini setting once a session is active. The call always failed silently.So PHP's own collector was left on whatever the platform default happened to be. It is then free to delete a session file the application still considers valid: an installation configured for a longer session than the platform default could have people logged out at the platform's number instead of its own.
The fix
Set it in
initialize(), before the session is started — the only moment PHP accepts it.The branch it came from still calls
getSessionLifeTime(), because that call has a side effect worth keeping: it resolves this session's own timeout and stores it. For a session that new, nothing else has — the timeout check above short-circuits while there is no recorded activity.Testing
A test that asserts the value PHP actually ends up with, and fails without the change (it reports the platform default). It also closes the session the harness starts in
setUp, so it asks what a real request asks — was this in place before the session existed? — rather than passing for the wrong reason.That closing now happens in the shared builder, which is what a request arriving with no active session looks like, and it removed a warning the neighbouring test had been raising for the same reason.
Unit suite green: 3062 tests.