php forking/spawning question...
| From: | bruce | Date: | Tue, 27 Jan 2009 20:28:37 +0000 |
| Subject: | php forking/spawning question... | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-287237@lists.php.net to get a copy of this message | ||
Hi...
got the follwoing example... basically, when i call the function "spawn_" i
get the passed vars for appname/args...
the $appname,$args are valid when the spawn_ function is initially invoked.
however, when the app does the fork, the $appname, $args get lost. when the
function gets to the pcntl_exec, the vars ($appname, $args) are no longer
set.
so what did i miss, how is this process supposed to work?
thoughts/comments...
thanks
=========================================================================
/*
test func to spawn client thread
*/
function spawn_($appname, $args)
{
print "appname =".$appname."\n";
print_r($args);
//exit();
$pid = pcntl_fork();
if ($pid == -1)
{
die('cannot fork');
}
elseif ($pid)
{
print "child pid = ".$pid."\n";
//pcntl_waitpid($pid, $status);
//break;
//exit();
$par=1;
}
else
{
// Note that pcntl_exec() automatically prepends the program
name
// to the array of arguments; the program name cannot be
spoofed.
print "running cmd \n";
pcntl_exec($appname, $args);
//system("./clientmgr.php");
exit();
}
}
--------------------------------------------------------------------