看來setCompleteCallback並不適用於我。我做錯了什麼?謝謝。Gearman 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;
}
?>
這是我的工作人員。仍然不起作用。也許我需要別的東西?
請給你看看工人腳本。 –
好吧,我的工作人員在後 – sandra1n