Post by fegdeed » Tue Oct 06, 2020 7:49 am

@letxobnav Thank you .

Active Member

Posts

Joined
Fri Sep 21, 2018 12:01 am

Post by by mona » Thu Oct 22, 2020 10:40 pm

The __destruct function in the class will not work for the database solution as the database connection is already gone.

Garbage collection for DB stored sessions.
system/library/session/db.php:

replace the __construct function with:

Code: Select all

public function __construct($registry) {
$this->db = $registry->get('db');

// session expire using php.ini, defaults to 1 hour
$this->expire = ini_get('session.gc_maxlifetime') ?? 3600;

// session garbage collection using php.ini, defaults to 1% probability
$gc_probability = ini_get('session.gc_probability') ?? 1;
$gc_divisor = ini_get('session.gc_divisor') ?? 100;
if ((rand() % $gc_divisor) < $gc_probability) $this->gc();
}
That will make sure the gc is actually called and sets the right divisor/probability settings

replace the gc function with:

Code: Select all

public function gc() {
$dt = date('Y-m-d H:i:s',((int)time()));
$this->db->query("DELETE FROM " . DB_PREFIX . "session WHERE expire < '".$dt."'");
}
That will make sure that the query compares datetime with datetime and not timestamp with datetime.

replace the read function with:

Code: Select all

public function read($session_id) {
$query = $this->db->query("SELECT data FROM " . DB_PREFIX . "session WHERE session_id = '" . $this->db->escape($session_id) . "'");
if ($query->num_rows) return json_decode($query->row['data'], true);
else return false;
}
That will remove the expire condition from the query as it slows the query down comparing timestamp with datetime.

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


Spinning Social : Links : Menus : Payments : Socials : Ads : Screen Backgrounds : Galleries : Headers : Banners : Promos


Active Member

Posts

Joined
Mon Jun 10, 2019 9:31 am
Who is online

Users browsing this forum: No registered users and 47 guests