How to set session timeout in Laravel?

In app/config/session.php you have:

lifetime

option that allow you to set session expire time in minutes (not in seconds)

'lifetime' => 60,

means that session will expire after an hour.

There is also one more setting here:

'expire_on_close' => true,

that decides if session will be expired when browser will be closed.

Other settings you could get interested is also php.ini values of:

session.cookie_lifetime = 0

and

session.gc_maxlifetime = 1440

Those are default values.

The first one means how long session cookie will be stored – default value is 0 (until browse is closed). The second option means after how many of seconds PHP may destroy this session data.

I said may because there is one other option session.gc_probability in php.ini file that decides what’s the chance of running garbage collector. Be default there is only 1% chance that after 1440 seconds (24 minutes) this session data will be destroyed.

Leave a Comment