Skip to content

Instantly share code, notes, and snippets.

@colindev
Last active November 27, 2017 08:07
Show Gist options
  • Save colindev/ec826f26a9eab368528a317deaf56749 to your computer and use it in GitHub Desktop.
Save colindev/ec826f26a9eab368528a317deaf56749 to your computer and use it in GitHub Desktop.
demo for php pcntl
<?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