PHP Gearman 任务有时返回空对象
我有一个简单的 Gearman 客户端和工作人员。我在我的 Ubuntu 桌面上运行这两个程序。我已经安装了 gearman-beta pecl 软件包和 synaptic 的 Gearman 版本。
我的问题是,有时我从工作人员那里得到一个空对象。大约 50% 的时间显示预期文本,其余时间显示“GearmanTask Object ( )”(来自客户端中的 print_r)
在任何时候都不会发生异常,客户端始终认为工作程序已成功完成。我还应该注意,没有任何超时,客户端脚本执行得
很快
$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();
}
}
。 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!';
}
我在 /var/log/gearman-job-server 中没有任何
想法?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能看起来很奇怪,但以下内容对我有用。
替换以下块
您应该用此
This might seem strange but the following worked for me.
You should replace the following block
with this