Comments (5)
Here is a patch for this bug I use:
When using mongodb as a session backend, the symfony driver uses hardcoded expiry time from php.ini.
This patch makes it accept an expiration time (seconds) as 'expiretime' in its options array.
--- vendor/symfony/http-foundation/Session/Storage/Handler/MongoDbSessionHandler.php.orig 2020-03-13 12:55:28.000000000 +0100
+++ vendor/symfony/http-foundation/Session/Storage/Handler/MongoDbSessionHandler.php 2020-03-13 13:24:19.223045994 +0100
@@ -88,6 +88,7 @@
'data_field' => 'data',
'time_field' => 'time',
'expiry_field' => 'expires_at',
+ 'expiretime' => (int) ini_get('session.gc_maxlifetime'),
], $options);
}
@@ -132,7 +133,7 @@
*/
protected function doWrite($sessionId, $data)
{
- $expiry = $this->createDateTime(time() + (int) ini_get('session.gc_maxlifetime'));
+ $expiry = $this->createDateTime(time() + (int) $this->options['expiretime']);
$fields = [
$this->options['time_field'] => $this->createDateTime(),
@@ -164,7 +165,7 @@
*/
public function updateTimestamp($sessionId, $data)
{
- $expiry = $this->createDateTime(time() + (int) ini_get('session.gc_maxlifetime'));
+ $expiry = $this->createDateTime(time() + (int) $this->options['expiretime']);
if ($this->mongo instanceof \MongoDB\Client) {
$methodName = 'updateOne';
--- vendor/jenssegers/mongodb-session/src/Jenssegers/Mongodb/Session/SessionManager.php.orig 2018-01-08 11:44:00.000000000 +0100
+++ vendor/jenssegers/mongodb-session/src/Jenssegers/Mongodb/Session/SessionManager.php 2020-03-13 13:25:52.324982735 +0100
@@ -63,7 +63,14 @@
*/
protected function getMongoDBOptions($database, $collection)
{
- return ['database' => $database, 'collection' => $collection, 'id_field' => '_id', 'data_field' => 'payload', 'time_field' => 'last_activity'];
+ return [
+ 'database' => $database,
+ 'collection' => $collection,
+ 'id_field' => '_id',
+ 'data_field' => 'payload',
+ 'time_field' => 'last_activity',
+ 'expiretime' => config('session.lifetime') * 60, // minutes to seconds
+ ];
}
/**
apply with patch -p0 -N -i fix_expiry.patch
in project root
from laravel-mongodb-session.
I'm having the same issue.
from laravel-mongodb-session.
This is coming upstream from https://github.com/symfony/http-foundation/blob/master/Session/Storage/Handler/MongoDbSessionHandler.php#L120
It seems to be hardcoded and not adjustable.
from laravel-mongodb-session.
same issue here. modify php.ini works.
from laravel-mongodb-session.
As workaround without monkey patching it to set the ini value in AppServiceProvider->boot();
public function boot() { ini_set('session.gc_maxlifetime', 7*24*60*60); }
Note that the specified lifetime are seconds and not minutes.
from laravel-mongodb-session.
Related Issues (20)
- Can`t install on L5 HOT 2
- How can i store login user _id in session collection HOT 1
- Just storing default fields. And also not being able to retrieve session Id from database. HOT 1
- Does not work with Laravel 5 HOT 6
- Problem with the new PHP MongoDB Extension HOT 1
- Laravel 6 support HOT 1
- Laravel 6 Not Installed HOT 1
- v1.4 not published
- Duplicate key in session when using different browser on same machine HOT 4
- Laravel 8 like database session driver HOT 1
- Laravel 9 support HOT 2
- Lumen 9 Support
- Doesn't work when mongo is not default. HOT 10
- Does the package use mongdbs TTL functionality? HOT 2
- Does it clear stale sessions? HOT 2
- another: Driver [mongodb] not supported HOT 3
- Getting error due to missing implementation of getDefaultDriver after 4.2 upgrade HOT 4
- session driver stopped working after jenssegers/laravel-mongodb update to 2.0.0 HOT 3
- CSRF filter always failing HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-mongodb-session.