]> git.mxchange.org Git - friendica.git/blob - src/Model/Process.php
Fix birthday display and setting
[friendica.git] / src / Model / Process.php
1 <?php
2 /**
3  * @file src/Model/Process.php
4  */
5 namespace Friendica\Model;
6
7 use Friendica\Database\DBA;
8 use Friendica\Util\DateTimeFormat;
9
10 /**
11  * functions for interacting with a process
12  */
13 class Process
14 {
15         /**
16          * Insert a new process row. If the pid parameter is omitted, we use the current pid
17          *
18          * @param string $command
19          * @param string $pid
20          * @return bool
21          * @throws \Exception
22          */
23         public static function insert($command, $pid = null)
24         {
25                 $return = true;
26
27                 if (is_null($pid)) {
28                         $pid = getmypid();
29                 }
30
31                 DBA::transaction();
32
33                 if (!DBA::exists('process', ['pid' => $pid])) {
34                         $return = DBA::insert('process', ['pid' => $pid, 'command' => $command, 'created' => DateTimeFormat::utcNow()]);
35                 }
36
37                 DBA::commit();
38
39                 return $return;
40         }
41
42         /**
43          * Remove a process row by pid. If the pid parameter is omitted, we use the current pid
44          *
45          * @param string $pid
46          * @return bool
47          * @throws \Exception
48          */
49         public static function deleteByPid($pid = null)
50         {
51                 if ($pid === null) {
52                         $pid = getmypid();
53                 }
54
55                 return DBA::delete('process', ['pid' => $pid]);
56         }
57
58         /**
59          * Clean the process table of inactive physical processes
60          */
61         public static function deleteInactive()
62         {
63                 DBA::transaction();
64
65                 $processes = DBA::select('process', ['pid']);
66                 while($process = DBA::fetch($processes)) {
67                         if (!posix_kill($process['pid'], 0)) {
68                                 self::deleteByPid($process['pid']);
69                         }
70                 }
71
72                 DBA::commit();
73         }
74 }