Last active
September 13, 2018 10:40
-
-
Save cosmos-sajal/cbb714bc85ad6b21d8ec0ccbdf5e54f4 to your computer and use it in GitHub Desktop.
creating and checking PID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param Integer $pid | |
* | |
* @return boolean | |
*/ | |
public function isProcessRunning($pid) | |
{ | |
if (file_exists("/proc/".$pid)) { | |
return true; | |
} | |
$this->createPIDFile(); | |
return false; | |
} | |
/** | |
* @return Integer | |
*/ | |
public function getProcessId() | |
{ | |
return getmypid(); | |
} | |
/** | |
* @return null | |
*/ | |
private function createPIDFile() | |
{ | |
file_put_contents( | |
"/home/ubuntu/<project_folder>/cron_pids/myCronPID.txt", | |
(string) $this->getProcessId(), | |
LOCK_EX | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment