Created
March 24, 2015 07:31
-
-
Save wgm89/2b7ae975d016dc8ff2a4 to your computer and use it in GitHub Desktop.
php pcntl_fork
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
| <?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