diff --git a/app/Console/Commands/DatabaseSessionGarbageCollector.php b/app/Console/Commands/DatabaseSessionGarbageCollector.php new file mode 100644 index 000000000..db11cb80d --- /dev/null +++ b/app/Console/Commands/DatabaseSessionGarbageCollector.php @@ -0,0 +1,56 @@ +whereNull('user_id')->delete(); + }); + + DB::transaction(function() { + $ts = now()->subMonths(3)->timestamp; + DB::table('sessions')->where('last_activity', '<', $ts)->delete(); + }); + + return Command::SUCCESS; + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 0dd65888a..dd1bae944 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -31,6 +31,7 @@ class Kernel extends ConsoleKernel $schedule->command('story:gc')->everyFiveMinutes(); $schedule->command('gc:failedjobs')->dailyAt(3); $schedule->command('gc:passwordreset')->dailyAt('09:41'); + $schedule->command('gc:sessions')->twiceDaily(13, 23); } /**