客户:
<?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
然后它写入文件,但外壳只是卡在
[user@server gearman]$ php worker.php
Starting
Result: tset a si siht
无论如何我可以让它在调用doBackground时在后台运行worker.php文件吗?我还想确保在重新启动 gearmand 时这项工作,以便在重新启动守护程序时我不必运行 worker.php。