似乎 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;
}
?>
这是我的工人。还是不行。也许我需要别的东西?