Skip to content

Tell PHP the configured session lifetime while it will still listen - #718

Merged
blaipr merged 1 commit into
mainfrom
fix/session-gc-lifetime
Aug 13, 2026
Merged

Tell PHP the configured session lifetime while it will still listen#718
blaipr merged 1 commit into
mainfrom
fix/session-gc-lifetime

Conversation

@blaipr

@blaipr blaipr commented Aug 13, 2026

Copy link
Copy Markdown
Member

The bug

Init tried to set session.gc_maxlifetime from initUserSession() — but Context::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.

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?
@blaipr
blaipr merged commit 26f5b5f into main Aug 13, 2026
8 checks passed
@blaipr
blaipr deleted the fix/session-gc-lifetime branch August 13, 2026 17:15
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

Successfully merging this pull request may close these issues.

1 participant