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:
That will make sure the gc is actually called and sets the right divisor/probability settings
replace the gc function with:
That will make sure that the query compares datetime with datetime and not timestamp with datetime.
replace the read function with:
That will remove the expire condition from the query as it slows the query down comparing timestamp with datetime.
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();
}
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."'");
}
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;
}
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
Who is online
Users browsing this forum: No registered users and 4 guests