Created
June 28, 2016 15:55
-
-
Save 131/30412b834001259d9d9755ec8ea6cd08 to your computer and use it in GitHub Desktop.
This file contains 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
<? | |
function stop(){ | |
if(!file_exists(self::PID_FILE)) | |
return; | |
$pid = file_get_contents(self::PID_FILE); | |
posix_kill($pid, SIGTERM); | |
unlink(self::PID_FILE); | |
rbx::ok("Stopped $pid"); | |
} | |
function start() { | |
$this->stop(); | |
$newpid = pcntl_fork(); | |
if ($newpid === -1) | |
die("Couldn't fork()!"); | |
if($newpid) //this is the parent, now self-destruct | |
exit(0); | |
//here is the child | |
posix_setsid(); // Become the session leader | |
sleep(1); | |
// Fork again, but now as session leader. | |
$newpid = pcntl_fork(); | |
if ($newpid === -1) | |
die("Couldn't fork()!"); | |
if ($newpid) | |
exit(0); // I'm the parent, and I'm going to self-destruct | |
$pid = posix_getpid(); | |
file_put_contents(self::PID_FILE, $pid); | |
rbx::ok("Master started with pid $pid"); | |
$this->workall(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment