Commit b3319f5d authored by Taylor Otwell's avatar Taylor Otwell

Merge pull request #1051 from franzliedke/patch-30

[Session] Trigger garbage collection (sweep) manually
parents 175683f9 228f5722
......@@ -298,13 +298,29 @@ class Payload {
$this->cookie($config);
// Some session drivers implement the Sweeper interface meaning that
// they must clean up expired sessions manually. If the driver is a
// sweeper, we'll calculate if we need to run garbage collection.
// they must clean up expired sessions manually. Here we'll calculate
// if we need to run garbage collection.
$sweepage = $config['sweepage'];
if ($this->driver instanceof Sweeper and (mt_rand(1, $sweepage[1]) <= $sweepage[0]))
if (mt_rand(1, $sweepage[1]) <= $sweepage[0])
{
$this->driver->sweep(time() - ($config['lifetime'] * 60));
$this->sweep();
}
}
/**
* Clean up expired sessions.
*
* If the session driver is a sweeper, it must clean up expired sessions
* from time to time. This method triggers garbage collection.
*
* @return void
*/
public function sweep()
{
if ($this->driver instanceof Sweeper)
{
$this->driver->sweep(time() - (Config::get('session.lifetime') * 60));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment