Session is lost after a few hours.. despite the timeout setting being 30 days

I am sure I’m doing something wrong, but I’m not clear what.

I have an issue that if a user walks away from their computer for a few hours, that their session data is lost. In config/main.php, I have this:

$config['components']['user'] = [
    'identityClass' => 'common\models\User',
    'enableAutoLogin' => true,
    'identityCookie' => ['name' => '_identity-frontend', 'httpOnly' => true],
];

$config['components']['session'] = [
    'name' => 'frontend',
    'timeout' => 30 * 24 * 3600, // 30 days
];

If I show this in debug output in a view (Yii::$app->session->timeout), it does indeed say 30 days.

Yet, if I leave my computer for several hours and come back, everything breaks and the user has to restart a session. Basically, a piece of app code breaks:

$model->requestBy = Yii::$app->session->get('requestBy');

This works… until it doesn’t and the session is no longer valid. I am using the php file method currently to debug this. What I find is that the session files in /var/lib/php/sessions go away and when the user creates a new session a new session file appears.

So I’m totally confused. What does Yii::$app->session->timeout do? And what do I need to do so that a session lasts for 30 days? Or even until they close their web browser (because currently they just have to walk away for several hours, even with the web browser and app page open)?

Check settings in php.ini, the settings in php.ini take precedence. From api: “The number of seconds after which data will be seen as ‘garbage’ and cleaned up. The default value is 1440 seconds (or the value of “session.gc_maxlifetime” set in php.ini).”
Read too: Handling Requests: Sessions and Cookies | The Definitive Guide to Yii 2.0 | Yii PHP Framework