return;
}
- $a->start_process();
+ Worker::startProcess();
logger("Front end worker started: ".getmypid());
Worker::unclaimProcess();
- $a->end_process();
+ Worker::endProcess();
logger("Front end worker ended: ".getmypid());
Worker::unclaimProcess();
-$a->end_process();
+Worker::endProcess();
killme();
namespace Friendica;
-use Friendica\Core\System;
use Friendica\Core\Cache;
use Friendica\Core\Config;
use Friendica\Core\PConfig;
-use Friendica\Database\DBM;
-
-use dba;
+use Friendica\Core\System;
use Detection\MobileDetect;
use Exception;
require_once 'boot.php';
-require_once 'include/dba.php';
+require_once 'include/text.php';
/**
*
$this->callstack[$value][$callstack] += (float) $duration;
}
- /**
- * @brief Log active processes into the "process" table
- */
- function start_process() {
- $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
-
- $command = basename($trace[0]['file']);
-
- $this->remove_inactive_processes();
-
- dba::transaction();
-
- $r = q('SELECT `pid` FROM `process` WHERE `pid` = %d', intval(getmypid()));
- if (!DBM::is_result($r)) {
- dba::insert('process', ['pid' => getmypid(), 'command' => $command, 'created' => datetime_convert()]);
- }
- dba::commit();
- }
-
- /**
- * @brief Remove inactive processes
- */
- function remove_inactive_processes() {
- dba::transaction();
-
- $r = q('SELECT `pid` FROM `process`');
- if (DBM::is_result($r)) {
- foreach ($r AS $process) {
- if (!posix_kill($process['pid'], 0)) {
- dba::delete('process', ['pid' => $process['pid']]);
- }
- }
- }
- dba::commit();
- }
-
- /**
- * @brief Remove the active process from the "process" table
- */
- function end_process() {
- dba::delete('process', ['pid' => getmypid()]);
- }
-
function get_useragent() {
return
FRIENDICA_PLATFORM . " '" .
*/
namespace Friendica\Core;
-use Friendica\App;
-use Friendica\Core\System;
use Friendica\Core\Config;
-use Friendica\Core\Worker;
+use Friendica\Core\System;
use Friendica\Database\DBM;
+use Friendica\Model\Process;
use Friendica\Util\Lock;
use dba;
}
// We now start the process. This is done after the load check since this could increase the load.
- $a->start_process();
+ self::startProcess();
// Kill stale processes every 5 minutes
$last_cleanup = Config::get('system', 'poller_last_cleaned', 0);
if (self::tooMuchWorkers()) {
// Cleaning dead processes
self::killStaleWorkers();
- get_app()->remove_inactive_processes();
+ Process::deleteInactive();
return;
}
return true;
}
+
+ /**
+ * Log active processes into the "process" table
+ *
+ * @brief Log active processes into the "process" table
+ */
+ public static function startProcess()
+ {
+ $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
+
+ $command = basename($trace[0]['file']);
+
+ Process::deleteInactive();
+
+ Process::insert($command);
+ }
+
+ /**
+ * Remove the active process from the "process" table
+ *
+ * @brief Remove the active process from the "process" table
+ * @return bool
+ */
+ public static function endProcess()
+ {
+ return Process::deleteByPid();
+ }
}
--- /dev/null
+<?php
+/**
+ * @file src/Model/Process.php
+ */
+namespace Friendica\Model;
+
+use Friendica\BaseObject;
+use dba;
+
+require_once 'include/dba.php';
+
+/**
+ * @brief functions for interacting with a process
+ */
+class Process extends BaseObject
+{
+ /**
+ * Insert a new process row. If the pid parameter is omitted, we use the current pid
+ *
+ * @param string $command
+ * @param string $pid
+ * @return bool
+ */
+ public static function insert($command, $pid = null)
+ {
+ dba::transaction();
+
+ if (!dba::exists('process', ['pid' => getmypid()])) {
+ $return = dba::insert('process', ['pid' => $pid, 'command' => $command, 'created' => datetime_convert()]);
+ }
+
+ dba::commit();
+
+ return $return;
+ }
+
+ /**
+ * Remove a process row by pid. If the pid parameter is omitted, we use the current pid
+ *
+ * @param string $pid
+ * @return bool
+ */
+ public static function deleteByPid($pid = null)
+ {
+ if ($pid === null) {
+ $pid = getmypid();
+ }
+
+ return dba::delete('process', ['pid' => $pid]);
+ }
+
+ /**
+ * Clean the process table of inactive physical processes
+ */
+ public static function deleteInactive()
+ {
+ dba::transaction();
+
+ $processes = dba::select('process', ['pid']);
+ while($process = dba::fetch($processes)) {
+ if (!posix_kill($process['pid'], 0)) {
+ self::deleteByPid($process['pid']);
+ }
+ }
+
+ dba::commit();
+ }
+}