Last active
November 27, 2017 08:07
-
-
Save colindev/ec826f26a9eab368528a317deaf56749 to your computer and use it in GitHub Desktop.
demo for php pcntl
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 | |
foreach (['a', 'b', 'c'] as $x) { | |
$pid = pcntl_fork(); | |
if ($pid === -1) { | |
echo 'fork Error'; | |
} elseif (!$pid) { | |
$i = 0; | |
while (true) { | |
$t = time(); | |
echo "sub(${x}, ${i}) ${t}\n"; | |
$i++; | |
if ($i >= 5) { | |
break; | |
} | |
sleep(3); | |
} | |
echo "sub(${x}, ${i})bye...\n"; | |
} | |
} | |
while (-1 !== pcntl_waitpid(0, $states)) { | |
$states = pcntl_wexitstatus($states); | |
echo "pcntl_wexitstatus = ${states}\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment