From 228f57226b5b6533ae0424e5c9bc60591855a997 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Fri, 3 Aug 2012 18:09:37 +0300 Subject: [PATCH] Extract sweep method in Session payload class. This allows for manually triggering garbage collection in session drivers. --- laravel/session/payload.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/laravel/session/payload.php b/laravel/session/payload.php index 1149951f..48aedd94 100644 --- a/laravel/session/payload.php +++ b/laravel/session/payload.php @@ -298,13 +298,29 @@ public function save() $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)); } }