PHP Gearman 任务有时返回空对象

发布于 2024-12-27 05:30:55 字数 1148 浏览 1 评论 0原文

我有一个简单的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

っ左 2025-01-03 05:30:55

这可能看起来很奇怪,但以下内容对我有用。

替换以下块

$gmclient = new GearmanClient();
$gmclient->addServer();

$gmclient->addTask('test','just some text');
$gmclient->setCompleteCallback("complete");
$gmclient->setFailCallback('fail');
$gmclient->runTasks();

您应该用此

$gmclient = new GearmanClient();
$gmclient->addServer();

$gmclient->setCompleteCallback("complete");
$gmclient->setFailCallback('fail');

$gmclient->addTask('test','just some text');
$gmclient->runTasks(); 

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(); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文