diff --git a/src/Drivers/Cookie.php b/src/Drivers/Cookie.php index 8805ccd..5d4857c 100644 --- a/src/Drivers/Cookie.php +++ b/src/Drivers/Cookie.php @@ -16,6 +16,7 @@ public function close(): bool return true; } + #[\ReturnTypeWillChange] public function read($id): string { return $this->get($_COOKIE[$id] ?? ''); @@ -36,8 +37,9 @@ public function destroy($id): bool return true; } - public function gc($max_lifetime): bool + #[\ReturnTypeWillChange] + public function gc($max_lifetime) { - return true; + return 0; } } \ No newline at end of file diff --git a/src/Drivers/File.php b/src/Drivers/File.php index 27f3836..5fb5024 100644 --- a/src/Drivers/File.php +++ b/src/Drivers/File.php @@ -20,6 +20,7 @@ public function close(): bool return true; } + #[\ReturnTypeWillChange] public function read($id): string { return $this->get((string) @file_get_contents("{$this->save_path}/sess_{$id}")); @@ -39,15 +40,19 @@ public function destroy($id): bool return true; } - public function gc($max_lifetime): bool + #[\ReturnTypeWillChange] + public function gc($max_lifetime) { $time = time(); + $count = 0; + foreach (glob("{$this->save_path}sess_*") as $file) { if (filemtime($file) + $max_lifetime < $time && file_exists($file)) { unlink($file); + $count++; } } - return true; + return $count; } } \ No newline at end of file diff --git a/src/Drivers/Memcached.php b/src/Drivers/Memcached.php index 14f3f66..847fb82 100644 --- a/src/Drivers/Memcached.php +++ b/src/Drivers/Memcached.php @@ -41,6 +41,7 @@ public function close(): bool return true; } + #[\ReturnTypeWillChange] public function read($id): string { return $this->get($this->conn->get("{$this->name}{$id}") ?: ''); @@ -56,8 +57,9 @@ public function destroy($id): bool return $this->conn->delete("{$this->name}{$id}"); } - public function gc($max_lifetime): bool + #[\ReturnTypeWillChange] + public function gc($max_lifetime) { - return true; + return 0; } } \ No newline at end of file diff --git a/src/Drivers/MySql.php b/src/Drivers/MySql.php index 85ac5cf..a96464d 100644 --- a/src/Drivers/MySql.php +++ b/src/Drivers/MySql.php @@ -86,14 +86,16 @@ public function destroy($id): bool return $completed; } - public function gc($max_lifetime): bool + #[\ReturnTypeWillChange] + public function gc($max_lifetime) { $max_lifetime = time() - $max_lifetime; $statement = $this->conn->prepare("DELETE FROM `{$this->table}` WHERE `time` < :time"); $statement->bindParam(':time', $max_lifetime, PDO::PARAM_INT); - $completed = $statement->execute(); + $statement->execute(); + $count = $statement->rowCount(); $statement = null; // close - return $completed; + return $count; } } \ No newline at end of file diff --git a/src/Drivers/Redis.php b/src/Drivers/Redis.php index c621bef..8ef6799 100644 --- a/src/Drivers/Redis.php +++ b/src/Drivers/Redis.php @@ -34,6 +34,7 @@ public function close(): bool return true; } + #[\ReturnTypeWillChange] public function read($id): string { return $this->get($this->conn->get("{$this->name}{$id}") ?: ''); @@ -49,8 +50,9 @@ public function destroy($id): bool return $this->conn->del("{$this->name}{$id}") > 0; } - public function gc($max_lifetime): bool + #[\ReturnTypeWillChange] + public function gc($max_lifetime) { - return true; + return 0; } } \ No newline at end of file diff --git a/src/default_config.php b/src/default_config.php index 3ef5086..4119c37 100644 --- a/src/default_config.php +++ b/src/default_config.php @@ -19,7 +19,8 @@ 'cookie_lifetime' => '0', # Specifies the lifetime of the cookie in seconds which is sent to the browser. The value 0 means "until the browser is closed." 'gc_maxlifetime' => '1440', # Specifies the number of seconds after which data will be seen as 'garbage' and potentially cleaned up. 'use_strict_mode' => '1', # Specifies whether the module will use strict session id mode. - 'gc_probability' => '1', # + 'gc_probability' => '1', # https://www.php.net/manual/en/session.configuration.php#ini.session.gc-probability + 'gc_divisor' => '100', # https://www.php.net/manual/en/session.configuration.php#ini.session.gc-divisor ], Session::CONFIG_MYSQL_DS => [