@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 33 lines 1.1 kB view raw
1<?php 2 3// TODO: See T13321. After the removal of daemon PID files this class 4// no longer makes as much sense as it once did. 5 6final class PhabricatorDaemonReference extends Phobject { 7 8 public static function isProcessRunning($pid) { 9 if (!$pid) { 10 return false; 11 } 12 13 if (function_exists('posix_kill')) { 14 // This may fail if we can't signal the process because we are running as 15 // a different user (for example, we are 'apache' and the process is some 16 // other user's, or we are a normal user and the process is root's), but 17 // we can check the error code to figure out if the process exists. 18 $is_running = posix_kill($pid, 0); 19 if (posix_get_last_error() == 1) { 20 // "Operation Not Permitted", indicates that the PID exists. If it 21 // doesn't, we'll get an error 3 ("No such process") instead. 22 $is_running = true; 23 } 24 } else { 25 // If we don't have the posix extension, just exec. 26 list($err) = exec_manual('ps %s', $pid); 27 $is_running = ($err == 0); 28 } 29 30 return $is_running; 31 } 32 33}