Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
815B

  1. <?php
  2. class pidfile {
  3. private $_file;
  4. private $_running;
  5. public function __construct($dir, $name) {
  6. $this->_file = "$dir/$name.pid";
  7. if (file_exists($this->_file)) {
  8. $pid = trim(@file_get_contents($this->_file));
  9. if (($pid != "") AND posix_kill($pid, 0)) {
  10. $this->_running = true;
  11. }
  12. }
  13. if (! $this->_running) {
  14. $pid = getmypid();
  15. file_put_contents($this->_file, $pid);
  16. }
  17. }
  18. public function __destruct() {
  19. if ((! $this->_running) && file_exists($this->_file)) {
  20. @unlink($this->_file);
  21. }
  22. }
  23. public function is_already_running() {
  24. return $this->_running;
  25. }
  26. public function running_time() {
  27. return(time() - @filectime($this->_file));
  28. }
  29. public function kill() {
  30. if (file_exists($this->_file))
  31. return(posix_kill(file_get_contents($this->_file), SIGTERM));
  32. }
  33. }