I have a simple Gearman client and worker. I am running both on my Ubuntu desktop. I have installed the gearman-beta pecl package and the version of Gearman from synaptic.
My problem is that sometimes I'm getting an empty object back from the worker. About 50% of the time it displays the expected text, the rest of the time it displays "GearmanTask Object ( )" (from my print_r in the client)
At no point is an exception happening, the client always thinks the worker completed successfully. I should also note that there aren't any timeouts, the client script executes quickly.
Client
$gmclient = new GearmanClient();
$gmclient->addServer();
$gmclient->addTask('test','just some text');
$gmclient->setCompleteCallback("complete");
$gmclient->setFailCallback('fail');
$gmclient->runTasks();
function fail() {
echo "FAIL";
}
function complete($task) {
print "COMPLETE: " . $task->data() . "<br />";
if($task->data() == '') {
echo '<pre>'.print_r($task, true).'</pre><br />';
echo $task->error();
}
}
Worker (test.php)
$worker = new GearmanWorker();
$worker->addServer();
$worker->addFunction("test", "test_function");
while (true) {
$worker->work();
print $worker->returnCode();
}
function test_function($job) {
return $job->workload() . ' worked!';
}
I don't have anything in /var/log/gearman-job-server.
Thoughts?
This might seem strange but the following worked for me.
You should replace the following block
$gmclient = new GearmanClient();
$gmclient->addServer();
$gmclient->addTask('test','just some text');
$gmclient->setCompleteCallback("complete");
$gmclient->setFailCallback('fail');
$gmclient->runTasks();
with this
$gmclient = new GearmanClient();
$gmclient->addServer();
$gmclient->setCompleteCallback("complete");
$gmclient->setFailCallback('fail');
$gmclient->addTask('test','just some text');
$gmclient->runTasks();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.