3 * @copyright Copyright (C) 2010-2021, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Model;
24 use Friendica\Database\Database;
25 use Friendica\Util\DateTimeFormat;
28 * functions for interacting with a process
35 public function __construct(Database $dba)
41 * Insert a new process row. If the pid parameter is omitted, we use the current pid
43 * @param string $command
44 * @param int $pid The process id to insert
48 public function insert(string $command, int $pid)
52 $this->dba->transaction();
54 if (!$this->dba->exists('process', ['pid' => $pid])) {
55 $return = $this->dba->insert('process', ['pid' => $pid, 'command' => $command, 'created' => DateTimeFormat::utcNow()]);
64 * Remove a process row by pid. If the pid parameter is omitted, we use the current pid
66 * @param int $pid The pid to delete
70 public function deleteByPid(int $pid)
72 return $this->dba->delete('process', ['pid' => $pid]);
76 * Clean the process table of inactive physical processes
78 public function deleteInactive()
80 $this->dba->transaction();
82 $processes = $this->dba->select('process', ['pid']);
83 while($process = $this->dba->fetch($processes)) {
84 if (!posix_kill($process['pid'], 0)) {
85 $this->deleteByPid($process['pid']);
88 $this->dba->close($processes);