-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Found a way to send info from the child to the parent. It would be easier if powerprocess included built in functions for this. The basic procedure is to call in the master during the setup the following commands:
$handle = ftok(FILE, chr(1));
$buffer = shm_attach($handle, 10240);
Then in the RunThreadCode part to spawn the tasks, include
$thread = sprintf("%05d",$ps->GetPID());
$output = shell_exec("php {$dir}/{$file} {$param} {$handle} {$thread}");
Also in the spawning routine (RunControlCode) call a function that checks upon the values of the children (however, I found that the children can't change the powerprocess object content themselves).You use $ps1 = shm_get_var($buffer, 1); to get the changes done in the children, and shm_put_var($buffer, 1, $ps); to update the date used by the children.
As to the children code
I grab the values sent over with
$buffer = shm_attach($argv[2]);
$pid = $argv[3];
wherever it seems apropriate i call a watchdog function which updates the values. In my case I am updating the time for the timeout value
function watchdog ()
{
global $buffer, $pid;
if (isset($buffer))
{
$ps = shm_get_var($buffer, 1);
if (isset($ps->myThreads[$pid]))
if ($ps->myThreads[$pid]['time'] != time())
{
$ps->myThreads[$pid]['time'] = time();
$lastto = time();
shm_put_var($buffer, 1, $ps);
// trigger_error($pid." ".$ps->myThreads[$pid]['time']);
}
}
}