]> git.mxchange.org Git - friendica.git/blob - include/pidfile.php
modified: view/theme/smoothly/style.css
[friendica.git] / include / pidfile.php
1 <?php
2 class pidfile {
3         private $_file;
4         private $_running;
5
6         public function __construct($dir, $name) {
7                 $this->_file = "$dir/$name.pid";
8
9                 if (file_exists($this->_file)) {
10                         $pid = trim(file_get_contents($this->_file));
11                         if (posix_kill($pid, 0)) {
12                                 $this->_running = true;
13                         }
14                 }
15
16                 if (! $this->_running) {
17                         $pid = getmypid();
18                         file_put_contents($this->_file, $pid);
19                 }
20         }
21
22         public function __destruct() {
23                 if ((! $this->_running) && file_exists($this->_file)) {
24                         unlink($this->_file);
25                 }
26         }
27
28         public function is_already_running() {
29                 return $this->_running;
30         }
31 }
32 ?>