GithubHelp home page GithubHelp logo

Comments (5)

MightyPork avatar MightyPork commented on September 28, 2024 1

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.

SimplyCorey avatar SimplyCorey commented on September 28, 2024

I'm having the same issue.

from laravel-mongodb-session.

SimplyCorey avatar SimplyCorey commented on September 28, 2024

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.

xiaodong-zhu avatar xiaodong-zhu commented on September 28, 2024

same issue here. modify php.ini works.

from laravel-mongodb-session.

tonivega avatar tonivega commented on September 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.