【问题标题】:Silex session set a lifetimeSilex 会话设置生命周期
【发布时间】:2015-07-09 05:28:55
【问题描述】:

如何更改 Silex 中的默认会话生命周期。 默认值为30mn;

文档http://silex.sensiolabs.org/doc/providers/session.html#usage 提供了线索,但没有显示如何执行此操作的示例。

当我这样设置会话时:

$app['session']->set('username', 'my username');

会话变量已设置,但它会在 3000 万后过期。

【问题讨论】:

标签: php symfony session session-cookies silex


【解决方案1】:

Silex 使用 Symfony 组件。您可以使用migrate 方法为某个会话设置过期时间。

例如:$app['session']->migrate(false, 3600);

Docs

设置所有会话的过期时间:

$app['session.storage.options'] = [
    'cookie_lifetime' => 3600
];

Source

【讨论】:

    【解决方案2】:

    不要忘记,Silex 中的生命周期设置与 php.ini 中的生命周期设置之间必须有一些一致性。

    默认情况下,PHP 生命周期会话设置为 1440 秒。如果您不更改此默认值,会话垃圾机制(由 /etc/cron.d/php5 运行)将删除“旧”会话(即 1440 秒不活动的会话)。

    这里是/etc/cron.d/php5的解释:

    #  This purges session files in session.save_path older than X,
    #  where X is defined in seconds as the largest value of
    #  session.gc_maxlifetime from all your SAPI php.ini files
    #  or 24 minutes if not defined.  The script triggers only
    #  when session.save_handler=files.
    #
    #  WARNING: The scripts tries hard to honour all relevant
    #  session PHP options, but if you do something unusual
    #  you have to disable this script and take care of your
    #  sessions yourself.
    

    【讨论】:

      猜你喜欢
      • 2017-11-08
      • 1970-01-01
      • 1970-01-01
      • 2011-09-15
      • 2012-04-07
      • 1970-01-01
      • 1970-01-01
      • 2011-08-21
      • 2016-11-21
      相关资源
      最近更新 更多