How to set session timeout in Laravel?

后端 未结 4 1080
礼貌的吻别
礼貌的吻别 2020-12-03 05:35

Is there an inherent way to setup sessions to expire after a certain time. My current setup seems to be expiring after 30 minutes and I would like to disable that or at leas

4条回答
  •  忘掉有多难
    2020-12-03 05:50

    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.

提交回复
热议问题