tags:

views:

179

answers:

1

I have the most basic script:

$pid = pcntl_fork();
if ($pid == -1) {
     die('could not fork');
} else if ($pid) {
     // we are the parent
     echo "parent done";
     pcntl_wait($status); //Protect against Zombie children
     echo "all done";
} else {
     // we are the child
     echo "Child finished";
}

When I run this, the output is always "Child finished". I'm running this on a lighttpd server.

A: 

Could be that your getting a signal from the child but it's not the exit status try some thing like:

do {
    pcntl_wait($status);
} while (!pcntl_wifexited($status));

To make sure the status is the exit one (SIGCHILD).

Neel
This has no effect.
Yegor
What output are you expecting? Try sleeping for a second before echoing child finished.
Neel
I expect to see "parent done" "all done". Sleep doesn't make a difference.
Yegor
fork may not behave quite how you expect it to when you're calling it from within lighttpd, I know they disable it in mod_php on Apache for this reason. Can you achieve the same goal using proc_open? http://uk3.php.net/manual/en/function.proc-open.php
Neel