6 public function __construct($dir, $name) {
7 $this->_file = "$dir/$name.pid";
9 if (file_exists($this->_file)) {
10 $pid = trim(@file_get_contents($this->_file));
11 if (($pid != "") AND posix_kill($pid, 0)) {
12 $this->_running = true;
16 if (! $this->_running) {
18 file_put_contents($this->_file, $pid);
22 public function __destruct() {
23 if ((! $this->_running) && file_exists($this->_file)) {
24 @unlink($this->_file);
28 public function is_already_running() {
29 return $this->_running;
32 public function running_time() {
33 return(time() - @filectime($this->_file));
36 public function kill() {
37 if (file_exists($this->_file))
38 return(posix_kill(file_get_contents($this->_file), SIGTERM));