Laravel会话超时剩余

时间:2018-10-02 18:20:12

标签: laravel laravel-5

关于检测会话是否超时有很多答案。我不是问这个。

我问,我怎样才能确切地知道用户的Laravel会话还剩下多少时间。

假设我正在使用最新版本的Laravel。

我非常想知道Laravel子系统认为本地/内置会话超时到期之前剩余的时间。

我强烈反对自己滚动或创建自己的各种自定义计时器。

这无关紧要,但是我的会话生存期设置配置(session.php)如下所示(如下)。而且我的.ENV设置也是SESSION_LIFETIME = 10。

 /*
    |--------------------------------------------------------------------------
    | Session Lifetime
    |--------------------------------------------------------------------------
    |
    | Here you may specify the number of minutes that you wish the session
    | to be allowed to remain idle before it expires. If you want them
    | to immediately expire on the browser closing, set that option.
    |
    */

    'lifetime' => env('SESSION_LIFETIME', 10),

1 个答案:

答案 0 :(得分:0)

此问题非常特定于正在使用的会话处理程序。如果您需要知道到期时间的剩余时间,则必须根据会话处理程序手动进行计算,如下所示:

  1. 文件会话处理程序:remaining time = last modified timestamp of file + session lifetime - current timestamp
  2. Cookie会话处理程序:remaining time = cookie expiry time - current time
  3. 数据库会话处理程序:remaining time = last_activity column value in session table + session lifetime - current timestamp
  4. 缓存会话处理程序:remaining time = cache ttl

会话驱动程序使用以下不同的会话处理程序实现:

  1. Cookie驱动程序:Cookie会话处理程序
  2. 文件驱动程序:文件会话处理程序
  3. 数据库驱动程序:数据库会话处理程序
  4. APC:缓存会话处理程序
  5. Memcached:缓存会话处理程序
  6. Redis:缓存会话处理程序
相关问题