Skip to content

Commit

Permalink
resolves issue #18
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghostff committed Jun 2, 2023
1 parent a8967ef commit d8f1e50
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/Drivers/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function close(): bool
return true;
}

#[\ReturnTypeWillChange]
public function read($id): string
{
return $this->get($_COOKIE[$id] ?? '');
Expand All @@ -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;
}
}
9 changes: 7 additions & 2 deletions src/Drivers/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}"));
Expand All @@ -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;
}
}
6 changes: 4 additions & 2 deletions src/Drivers/Memcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}") ?: '');
Expand All @@ -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;
}
}
8 changes: 5 additions & 3 deletions src/Drivers/MySql.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
6 changes: 4 additions & 2 deletions src/Drivers/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}") ?: '');
Expand All @@ -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;
}
}
3 changes: 2 additions & 1 deletion src/default_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 => [
Expand Down

0 comments on commit d8f1e50

Please sign in to comment.