0

I am trying to start a child process from parent when its terminated normally or due to an error.Using pcntl_waitpid, It become possible to get status from child. By that status I want restart the same script or process again. Here is an example.

<?php
    for ($i = 1; $i <= 5; ++$i) {
        $pid = pcntl_fork();

        if (!$pid) {
            sleep(1);
            print "In child $i\n";
            exit($i);
        }
    }

    while (pcntl_waitpid(0, $status) != -1) {
        $status = pcntl_wexitstatus($status);
        echo "Child $status completed\n";
    }
?>

How can it possible? Thanks in advance.

user2764644
  • 11
  • 1
  • 4

1 Answers1

0

Try

echo $i;
break; 

instead

exit($i);
MD SHAHIDUL ISLAM
  • 14,325
  • 6
  • 82
  • 89