【发布时间】:2015-11-06 05:08:08
【问题描述】:
我正在使用 Silex 构建一个小型后台项目,并使用 PdoSessionHandler 在数据库中存储会话。我已经成功地将会话存储在数据库中,但似乎将 cookie_lifetime 参数设置为 $app 变量会更改 cookie 的过期时间,但不会更改数据库中的会话生命周期。
$app->register(new Silex\Provider\SessionServiceProvider(), [
'session.storage.options' => [
'name' => '_PROJECTBACKOFFICE',
'cookie_lifetime' => 15552000,
],
]);
查看PdoSessionHandler的代码后,看起来数据库中会话生命周期的值取自php.ini设置session.gc_maxlifetime的值:
$maxlifetime = (int) ini_get('session.gc_maxlifetime');
并将值存储到数据库字段中
$mergeStmt = $this->pdo->prepare($mergeSql);
$mergeStmt->bindParam(':id', $sessionId, \PDO::PARAM_STR);
$mergeStmt->bindParam(':data', $data, \PDO::PARAM_LOB);
$mergeStmt->bindParam(':lifetime', $maxlifetime, \PDO::PARAM_INT);
因此,看来增加会话生命周期的唯一方法是更改 php.ini 设置。有没有人成功地以编程方式改变数据库的生命周期?
【问题讨论】:
标签: php symfony session session-cookies silex