且构网

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

Laravel 5 会话生命周期

更新时间:2023-01-25 17:21:26

检查您的 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 文件中.