- Apr 17, 2003
- 910
- 0
- 0
PHP has had a nifty little fork function that lets you spawn child processes from the parent process. It's great for speeding up certain things...my question is this.
When I call the function pcntl_fork() which spawns a child, does the execution within the child process start from the top OR does it simply continue from the point at which the fork function was called.
Example:
# 1 - doing stuff as parent process
$pid = pcntl_fork();
if(!$pid) {
# 2 - doing some stuff as child process
}
# 3 - this is where theads come to die
exit();
In that example, after I call the fork funtion, will the execution start again from #1 or will it just continue from #2?
Second question - PHP notes say that the DB connection will drop out when a child process exits, but this doesn't make sense to me if in fact each child is its own process - it should not affect the parent process' resources. What is the best way to maintain a DB connection until the parent and all child processes finish? I don't want something that results in a crapload of zombie processes either.
When I call the function pcntl_fork() which spawns a child, does the execution within the child process start from the top OR does it simply continue from the point at which the fork function was called.
Example:
# 1 - doing stuff as parent process
$pid = pcntl_fork();
if(!$pid) {
# 2 - doing some stuff as child process
}
# 3 - this is where theads come to die
exit();
In that example, after I call the fork funtion, will the execution start again from #1 or will it just continue from #2?
Second question - PHP notes say that the DB connection will drop out when a child process exits, but this doesn't make sense to me if in fact each child is its own process - it should not affect the parent process' resources. What is the best way to maintain a DB connection until the parent and all child processes finish? I don't want something that results in a crapload of zombie processes either.
