如何在 Laravel 中设置会话超时? [英] How to set session timeout in Laravel?

查看:104
本文介绍了如何在 Laravel 中设置会话超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种固有的方法可以将会话设置为在特定时间后过期.我当前的设置似乎在 30 分钟后到期,我想禁用它或至少增加它,但我在 Laravel 中找不到任何可以设置它的地方?

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 least increase it, but I can't find any places in Laravel where this could be set?

推荐答案

app/config/session.php 你有:

生命周期

允许您以分钟为单位设置会话过期时间的选项

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

'lifetime' => 60,

表示会话将在一个小时后过期.

means that session will expire after an hour.

这里还有一个设置:

'expire_on_close' => true,

决定当浏览器关闭时会话是否过期.

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

您可能感兴趣的其他设置还有 php.ini 值:

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

session.cookie_lifetime = 0

session.gc_maxlifetime = 1440

这些是默认值.

第一个表示会话 cookie 将存储多长时间 - 默认值为 0(直到浏览关闭).第二个选项表示在多少之后 PHP 可能会破坏此会话数据.

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.

我说可能是因为在 php.ini 文件中有另一个选项 session.gc_probability 决定了运行垃圾收集器的机会.默认情况下,只有 1% 的机会在 1440 秒(24 分钟)后此会话数据将被销毁.

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.

这篇关于如何在 Laravel 中设置会话超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆