似乎setCompleteCallback不对我工作。我做错了什么?感谢。
<?php
# Create our client object.
$client = new GearmanClient();
# Add default server (localhost).
$client->addServer("127.0.0.1", 4730);
echo "Sending job\n";
$client->addTask("reverse", "Hello!", null, "1");
$client->addTask("reverse", "Hello!", null, "2");
$client->setCompleteCallback("complete");
$client->runTasks();
function complete($task)
{
print "Выполнено: " . $task->unique() . ", " . $task->data() . "\n";
}
?>
修改
<?php
$worker = new GearmanWorker();
$worker->addServer("127.0.0.1", 4730);
$worker->addFunction("reverse", "reverse_fn");
while (1) {
$ret = $worker->work();
if ($worker->returnCode() != GEARMAN_SUCCESS)
break;
}
function reverse_fn($job)
{
$workload = $job->workload();
sleep(5);
$result = strrev($workload);
$job->sendComplete($result);
return $result;
}
?>
这是我的工作人员。仍然没有用。也许我需要别的东西?
答案 0 :(得分:4)
您应该在添加任务之前设置完整的回调。
$client->setCompleteCallback("complete");
$client->addTask("reverse", "Hello!", null, "1");
$client->addTask("reverse", "Hello!", null, "2");
答案 1 :(得分:0)
您必须在工作人员脚本中发送完整状态。 GearmanJob::sendComplete