客户端:
<?php
$gmclient= new GearmanClient();
$gmclient->addServer();
$gmclient->doBackground("reverse", "this is a test");
echo "done!\n";
工人:
<?php
echo "Starting\n";
$gmworker= new GearmanWorker();
$gmworker->addServer();
$gmworker->addFunction("reverse", "reverse_fn");
while($gmworker->work()){}
function reverse_fn($job)
{
$result= strrev($job->workload());
$fp = fopen('test.txt', 'a');
fwrite($fp, $result);
fclose($fp);
echo "Result: $result\n";
return $result;
}
?>
问题是,当我打电话给客户端时,没有任何事情发生,直到我运行
php worker.php
然后它写入文件,但shell只是停留在
[user@server gearman]$ php worker.php
Starting
Result: tset a si siht
无论如何我可以这样做,当它调用doBackground时,它会在后台运行worker.php文件吗?我还想确保在重新启动gearmand时这项工作,以便在重新启动守护程序时不必运行worker.php。