Silex 会话设置生命周期

Silex session set a lifetime

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

文档 http://silex.sensiolabs.org/doc/providers/session.html#usage 提供了线索,但没有说明如何操作。

当我这样设置会话时:

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

会话变量已设置,但将在 3000 万后到期。

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

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

Docs

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

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

Source

不要忘记,Silex 中的生命周期设置与 php.ini 中的生命周期设置必须保持一致。

默认情况下,PHP 生命周期会话设置为 1440 秒。如果您不更改此默认值,会话垃圾机制(运行 by /etc/cron.d/php5)将删除 "old" 个会话(即 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.