Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cakephp 3 how to increase session timeout

does anyone knows how to increase the session timeout in cakephp 3, no matter how I tried, it just timeout at 15 min,

the latest thing, I tried is to

change this setting at app.php file, but it still timeout at around 15 min, which is quite fustrating

'Session' => [
        'defaults' => 'php',
            'timeout'=>300*60//in minutes
    ],

Thank you

like image 934
cakephp_dev1 Avatar asked Jul 18 '26 12:07

cakephp_dev1


1 Answers

There's session timeout, and there's session cookie lifetime. The latter isn't affected by the former, which is configurable in the CakePHP configuration as shown in your code snippet, and is handled by CakePHPs session handler.

Check your PHP installations session.cookie_lifetime setting, it might be the cause of the issue. If you need to change it, either do that in your php.ini, or use the ini option in the CakePHP session configuration.

Quote from the docs:

By default PHP sets the session cookie to expire as soon as the browser is closed, regardless of the configured Session.timeout value. The cookie timeout is controlled by the session.cookie_lifetime ini value and can be configured using:

Configure::write('Session', [
    'defaults' => 'php',
    'ini' => [
        // Invalidate the cookie after 30 minutes without visiting
        // any page on the site.
        'session.cookie_lifetime' => 1800
    ]
]);

The difference between Session.timeout and the session.cookie_lifetime value is that the latter relies on the client telling the truth about the cookie. If you require stricter timeout checking, without relying on what the client reports, you should use Session.timeout.

Cookbook > Sessions > Session Configuration

If that doesn't fix the problem, then you'll have to do some debugging, check the session cookies expiration value, hook into CakePHPs session handler to figure whether this is where the session is being killed (\Cake\Network\Session::_timedOut()), etc...

like image 65
ndm Avatar answered Jul 21 '26 04:07

ndm