我是 php-gearman 的新手,在一些有用的教程的帮助下,我尝试了一些示例。就像上面的基本代码一样。
客户端
<?php
# Create our client object.
$client= new GearmanClient();
# Add default server (localhost).
$client->addServer("localhost", 4730);
echo "Sending job\n";
# Send reverse job
$result = $client->doBackground("reverse", "Hello!");
$stat = $client->jobStatus($result);
$done = false;
$client->setWorkloadCallback('test');
function test($data)
{
echo $data;
}
while(!$done)
{
if(!$stat[0])
{
$done = true;
echo $result;
}
echo "status".json_encode($stat)."/n";
$stat = $client->jobStatus($result);
}
?>
服务器端
<?php
# Create our worker object.
$worker= new GearmanWorker();
# Add default server (localhost).
$worker->addServer("localhost", 4730);
# Register function "reverse" with the server.
$worker->addFunction("reverse", "reverse_fn");
while (1)
{
print "Waiting for job...\n";
$ret= $worker->work();
if ($worker->returnCode() != GEARMAN_SUCCESS)
break;
}
function reverse_fn($job)
{
$workload= $job->workload();
echo "Received job: " . $job->handle() . "\n";
echo "Workload: $workload\n";
$result= strrev($workload);
echo "Result: $result\n";
return $result;
}
?>
这段代码让我得到工作状态。
我的问题是,在使用 GermanClient::doBackground 成功执行工作人员后如何获取返回的数据?