From ced417da6c2f3bcc37d747bbc5058d3e32767a67 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 6 Jan 2021 23:05:55 +0000 Subject: [PATCH] Added functionality to kill processes --- src/Worker/Cron.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/Worker/Cron.php b/src/Worker/Cron.php index 1901766d3..1f1e91630 100644 --- a/src/Worker/Cron.php +++ b/src/Worker/Cron.php @@ -24,6 +24,7 @@ namespace Friendica\Worker; use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\Core\Worker; +use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Tag; @@ -54,6 +55,10 @@ class Cron copy($basepath . '/.htaccess-dist', $basepath . '/.htaccess'); } + if (DI::config()->get('system', 'delete_sleeping_processes')) { + self::deleteSleepingProcesses(); + } + // Fork the cron jobs in separate parts to avoid problems when one of them is crashing Hook::fork(PRIORITY_MEDIUM, 'cron'); @@ -137,4 +142,26 @@ class Cron DI::config()->set('system', 'last_cron', time()); } + + /** + * Kill sleeping database processes + * + * @return void + */ + private static function deleteSleepingProcesses() + { + Logger::info('Looking for sleeping processes'); + + $processes = DBA::p("SHOW FULL PROCESSLIST"); + while ($process = DBA::fetch($processes)) { + // To-Do: Auf Datenbank abgrenzen + if (($process['Command'] != 'Sleep') || ($process['Time'] < 60) || ($process['db'] != DBA::databaseName())) { + continue; + } + + DBA::e("KILL ?", $process['Id']); + Logger::notice('Killed sleeping process', ['id' => $process['Id']]); + } + DBA::close($processes); + } }