Re: [PHP] Fork and zombies

2009-03-17 Thread Per Jessen
Waynn Lue wrote: > Ah, I was changing it to waiting for each child to finish in order to > see if I could narrow down my db problem, because I figure this should > be more or > less equivalent to running it synchronously. Even like this, though, > it still causes the db problem. I think the data

Re: [PHP] Fork and zombies

2009-03-17 Thread Waynn Lue
> > I think your waitpid() is in the wrong place, and at least you need use > WNOHANG - unless you specifically want to wait for each child to finish > before starting another one. > > > But it still has the same problem, and I'm also trying to avoid > > pcntl_wait or pcntl_waitpid at all because I

Re: [PHP] Fork and zombies

2009-03-17 Thread Per Jessen
Waynn Lue wrote: > I actually tried this in the meantime: > > $pid = pcntl_fork(); > if ($pid == -1) { > die("could not fork"); > } else if ($pid) { > // parent, return the child pid > echo "child pid $pid waiting\n"; > pcntl_waitpid($pid, $status); > if (pcntl_wifexited

Re: [PHP] Fork and zombies

2009-03-17 Thread Waynn Lue
> > > Here's pseudo code for what I'm trying to do: > > > > foreach ($things as $thing) { > > info = getInfo($thing); // uses a db connection > > makeApiCall(info); > > } > > > > makeApiCall(info) { > > $pid = pcntl_fork(); > > if ($pid == -1) { > > die("could not fork"); > > } else if ($

Re: [PHP] Fork and zombies

2009-03-17 Thread Per Jessen
Waynn Lue wrote: > Here's pseudo code for what I'm trying to do: > > foreach ($things as $thing) { > info = getInfo($thing); // uses a db connection > makeApiCall(info); > } > > makeApiCall(info) { > $pid = pcntl_fork(); > if ($pid == -1) { > die("could not fork"); > } else if ($pid) {

Re: [PHP] Fork and zombies

2009-03-16 Thread Waynn Lue
> > >> > While this works, it unfortunately leaves behind a zombie process > >> > every single time. > >> > >> You need to call pcntl_wait() or pcntl_waitpid(). > >> > > > > Right, but if I do that, then the parent has to wait until the child > > completes before it exits. > > No it doesn't - just

Re: [PHP] Fork and zombies

2009-03-16 Thread Per Jessen
Waynn Lue wrote: >> > While this works, it unfortunately leaves behind a zombie process >> > every single time. >> >> You need to call pcntl_wait() or pcntl_waitpid(). >> > > Right, but if I do that, then the parent has to wait until the child > completes before it exits. No it doesn't - just

Re: [PHP] Fork and zombies

2009-03-16 Thread Waynn Lue
> > Waynn Lue wrote: > > > I periodically run a script that makes a call against a remote API, > > which > > takes some time to return. In an attempt to increase thoroughput, I > > decided to investigate using pnctl_fork to spawn off multiple > > processes to make the call, since the slowest part

Re: [PHP] Fork and zombies

2009-03-16 Thread Per Jessen
Waynn Lue wrote: > I periodically run a script that makes a call against a remote API, > which > takes some time to return. In an attempt to increase thoroughput, I > decided to investigate using pnctl_fork to spawn off multiple > processes to make the call, since the slowest part is the network

[PHP] Fork and zombies

2009-03-16 Thread Waynn Lue
I periodically run a script that makes a call against a remote API, which takes some time to return. In an attempt to increase thoroughput, I decided to investigate using pnctl_fork to spawn off multiple processes to make the call, since the slowest part is the network part of it (and waiting for