cakephp: Session.timeout does not override anything
Description
The Session.timeout configuration option does not actually override the Session handler timeout value. Looking here, we can see a config array value being set using 60 * user override:
https://github.com/cakephp/cakephp/blob/5.x/src/Http/Session.php#L222-L224
But a few lines down, the value created above is not used:
https://github.com/cakephp/cakephp/blob/5.x/src/Http/Session.php#L243
Because of this, sessions timeout regardless of what the users have set in their config/app.php for Session timeout.
'Session' => [
'defaults' => 'php',
'timeout' => 0
],
CakePHP Version
5.0.4
PHP Version
8.2.11
About this issue
- Original URL
- State: closed
- Created 6 months ago
- Comments: 15 (8 by maintainers)
Commits related to this issue
- Clarify session documentation further Refs cakephp/cakephp#17513 — committed to cakephp/docs by markstory 6 months ago
- Improve session configuration doc block Refs cakephp/cakephp#17513 — committed to cakephp/app by markstory 6 months ago
- Tweak session doc block Refs cakephp/cakephp#17513 — committed to cakephp/cakephp by markstory 6 months ago
- Increase session gc lifetime When sessions have serverside timeouts disabled we should set a longer session.gc_maxlifetime option as using 0 could result in all sessions being reaped when a GC sweep ... — committed to cakephp/cakephp by markstory 6 months ago
- Increase session gc lifetime When sessions have serverside timeouts disabled we should set a longer session.gc_maxlifetime option as using 0 could result in all sessions being reaped when a GC sweep ... — committed to celsowm/cakephp by markstory 6 months ago
- Increase session gc lifetime When sessions have serverside timeouts disabled we should set a longer session.gc_maxlifetime option as using 0 could result in all sessions being reaped when a GC sweep ... — committed to celsowm/cakephp by markstory 6 months ago
- Add FunctionsBuilder::jsonValue() Merge changes from cakephp/cakephp#17171 Squashed commit of the following: commit 352b47ac01e1b35791d9237b8ad107f54ef17edc Merge: 7bbf221e25 f6cbbb4526 Author: cel... — committed to cakephp/cakephp by markstory 5 months ago
- Tweak session doc block Refs cakephp/cakephp#17513 — committed to cakephp/http by markstory 6 months ago
i applied it. also commented on the PR regarding a better default.
Oh, I found the real issue here.
The above debug die results in this:
We can see that
session.gc_maxlifetimedoes not exist in config[‘ini’]. But why not? It’s because of int(0) evaluating to false:https://github.com/cakephp/cakephp/blob/e8601c848cfc92af5aebc3d13ed7434cb333e4e8/src/Http/Session.php#L222
I’m trying to set an int(0) timeout value, but
if ($config['timeout'])evals to false, thus the line of code which should createconfig['ini']['session.gc_maxlifetime']does not run and thusoptions()does not modify the ini session.gc_maxlifetime and thus $_lifetime is never modified.good grief. we both missed that. 😃
I modified the check. The default value of timeout is null. If any other value is provided, the block executes and the ini override is set.
New result from above die(sprintf()):
And that works!