3 * @file src/Util/Pidfile.php
5 namespace Friendica\Util;
16 * @param string $dir path
17 * @param string $name filename
20 public function __construct($dir, $name)
22 $this->_file = "$dir/$name.pid";
24 if (file_exists($this->_file)) {
25 $pid = trim(@file_get_contents($this->file));
26 if (($pid != "") && posix_kill($pid, 0)) {
27 $this->running = true;
31 if (! $this->running) {
33 file_put_contents($this->file, $pid);
40 public function __destruct()
42 if ((! $this->running) && file_exists($this->file)) {
50 public static function isRunning()
52 return self::$running;
58 public static function runningTime()
60 return time() - @filectime(self::$file);
66 public static function kill()
68 if (file_exists(self::$file)) {
69 return posix_kill(file_get_contents(self::$file), SIGTERM);