From 5b5230f288cc18b56594a723f0d491ef3182eecd Mon Sep 17 00:00:00 2001 From: Joanhey Date: Sat, 15 Jul 2023 20:56:27 +0200 Subject: [PATCH] Small update to Session.php --- src/Session.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Session.php b/src/Session.php index 92bbec5..4ca0d1e 100644 --- a/src/Session.php +++ b/src/Session.php @@ -85,11 +85,11 @@ public static function sessionInit() } if (! static::$sessionSavePath) { - $savePath = ini_get('session.save_path'); - if (preg_match('/^\d+;(.*)$/', $savePath, $match)) { + $savePath = \ini_get('session.save_path'); + if (\preg_match('/^\d+;(.*)$/', $savePath, $match)) { $savePath = $match[1]; } - if (! $savePath || str_starts_with($savePath, 'tcp://')) { + if (! $savePath || \str_starts_with($savePath, 'tcp://')) { $savePath = \sys_get_temp_dir(); } static::$sessionSavePath = $savePath; @@ -105,11 +105,9 @@ public static function sessionInit() static::$sessionCookieSecure = (bool) \ini_get('session.cookie_secure'); static::$sessionCookieHttponly = (bool) \ini_get('session.cookie_httponly'); - if (class_exists(Timer::class)) { - Timer::add(static::$sessionGcInterval, function () { - static::tryGcSessions(); - }); - } + Timer::add(static::$sessionGcInterval, function () { + static::tryGcSessions(); + }); } /** @@ -119,7 +117,7 @@ public static function sessionCreateId(): string { \mt_srand(); - return bin2hex(\pack('d', \hrtime(true)).\pack('N', \mt_rand(0, 2147483647))); + return \bin2hex(\pack('d', \hrtime(true)).\pack('N', \mt_rand(0, 2147483647))); } /** @@ -254,7 +252,7 @@ public static function sessionRegenerateId(bool $delete_old_session = false): bo public static function tryGcSessions() { $time_now = \time(); - foreach (glob(static::$sessionSavePath.'/ses*') as $file) { + foreach (\glob(static::$sessionSavePath.'/ses*') as $file) { if (\is_file($file) && $time_now - \filemtime($file) > static::$sessionGcMaxLifeTime) { \unlink($file); }