Skip to content

Commit

Permalink
Small update to Session.php
Browse files Browse the repository at this point in the history
  • Loading branch information
joanhey committed Jul 15, 2023
1 parent 1edce1c commit 5b5230f
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
});
}

/**
Expand All @@ -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)));
}

/**
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 5b5230f

Please sign in to comment.