且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Laravel 5会话生命周期

更新时间:2023-01-25 17:17:02

检查您的php.ini:

Check your php.ini for:

session.gc_maxlifetime -默认1440秒-24分钟

session.gc_maxlifetime - Default 1440 secs - 24 mins

session.gc_maxlifetime 指定秒数,在此秒数之后,数据将被视为垃圾"并可能被清除.垃圾收集可能在会话启动期间发生(取决于session.gc_probability和session.gc_divisor).

session.gc_maxlifetime specifies the number of seconds after which data will be seen as 'garbage' and potentially cleaned up. Garbage collection may occur during session start (depending on session.gc_probability and session.gc_divisor).

session.cookie_lifetime -默认值0

session.cookie_lifetime 指定发送到浏览器的cookie的生存时间(以秒为单位).值0表示直到浏览器关闭".默认值为0.另请参见session_get_cookie_params()和session_set_cookie_params().

session.cookie_lifetime specifies the lifetime of the cookie in seconds which is sent to the browser. The value 0 means "until the browser is closed." Defaults to 0. See also session_get_cookie_params() and session_set_cookie_params().

如果时间少于Laravel配置,则将删除cookie,因为本地php.ini具有对Laravel配置的首选项.

In case it is less time than the Laravel configuration, the cookie will be removed because the local php.ini have preference over Laravel configuration.

您可以增加它或评论/删除.

You can just increase it or comment/delete.

如果未解决,则您的应用程序上的某些内容会破坏会话.

In case is not solved something on your App is destroying the session.

更新

发布后 v5.5.22 会话生存期是从.env,并且不再在config/session.php处进行硬编码,因此更改了

After release v5.5.22 session lifetime is loaded from .env and is not hardcoded anymore at config/session.php, changes there.

现在您可以使用以下方法修改会话生存期:

Now you can modify the session lifetime using:

SESSION_LIFETIME=

在您的.env文件中.