Skip to content

Instantly share code, notes, and snippets.

@wgm89
Created March 24, 2015 07:31
Show Gist options
  • Select an option

  • Save wgm89/2b7ae975d016dc8ff2a4 to your computer and use it in GitHub Desktop.

Select an option

Save wgm89/2b7ae975d016dc8ff2a4 to your computer and use it in GitHub Desktop.
php pcntl_fork
<?php
$pid = pcntl_fork();
if ($pid == -1) {
die('could not fork');
} else if ($pid) {
pcntl_waitpid($pid, $status, WUNTRACED); //Protect against Zombie children
if (pcntl_wifexited($status)) {
echo "Child exited normally";
} else if (pcntl_wifstopped($status)) {
echo "Signal: ", pcntl_wstopsig($status), " caused this child to stop.";
} else if (pcntl_wifsignaled($status)) {
echo "Signal: ",pcntl_wtermsig($status)," caused this child to exit with return code: ", pcntl_wexitstatus($status);
}
} else {
$test = "tail -n 1 -f /var/www/access.log";
$fp = popen($test, "r");
while (!feof($fp)) {
$out = fgets($fp, 4096);
}
pclose($fp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment