Can't set session lifetime with PDOSessionHandler Silex

Wednesday, November 4, 2015

I'm building a small backoffice project with Silex and I'm using the PdoSessionHandler to store sessions in the database. I've already succeded at storing the session in database but it seems that setting cookie_lifetime parameter to the $app variable changes the expiration of the cookie but not the session lifetime in database.



$app->register(new Silex\Provider\SessionServiceProvider(), [
'session.storage.options' => [
'name' => '_PROJECTBACKOFFICE',
'cookie_lifetime' => 15552000,
],
]);


After taking a look at the code of PdoSessionHandler looks like the value of the session lifetime in database takes the value from the php.ini setting session.gc_maxlifetime:



$maxlifetime = (int) ini_get('session.gc_maxlifetime');


And stores the value into the database field



$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);


So, looks like the only way to increase the session lifetime is by changing the php.ini setting. Has anyone succeded in changing the lifetime in database programatically?

0 comments:

Post a Comment