Skip to content

Instantly share code, notes, and snippets.

@cosmos-sajal
Last active September 13, 2018 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cosmos-sajal/cbb714bc85ad6b21d8ec0ccbdf5e54f4 to your computer and use it in GitHub Desktop.
Save cosmos-sajal/cbb714bc85ad6b21d8ec0ccbdf5e54f4 to your computer and use it in GitHub Desktop.
creating and checking PID
/**
* @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