2015-04-29 93 views

回答

2

Silex使用Symfony組件。您可以使用migrate方法爲某個會話設置到期。

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

Docs

要爲所有會話過期:

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

Source

1

不要忘記,你必須在生存期設置之間一定的一致性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.