PHP Gearman任务没有返回jobHandle(PHP Gearman tasks not returning jobHandle)

编程入门 行业动态 更新时间:2024-10-26 12:32:20
PHP Gearman任务没有返回jobHandle(PHP Gearman tasks not returning jobHandle)

我们正在使用Gearman,什么时候使用doLowBackground或doHigh这样的方法,这些都会返回jobHandle,但是当我们执行任务时 ,没有jobHandle对象。 我们得到GearmanTask对象,而不是获取jobHandle,我们得到string(0) ""

什么可能导致这个?

谢谢!

编辑:这是代码和其他信息:

// $client = \GearmanClient; // servers added, all that jazz // $workload = 'string'; $arguments = array( 'handleJob', $workload ); $task = call_user_func_array(array($client, $method), $arguments); if ($task instanceof GearmanTask) { $handles[] = $task->jobHandle(); } $data = $client->runTasks();

任务正确运行但$handle正在填充空字符串(每个任务添加一个)

编辑:这是我们得到的回应:

object(GearmanTask)#294 (0) { }

我已经抛弃了所有PECL齿轮手对象,没有任何东西显示,这里是客户端,填充了服务器,选项等

object(GearmanClient)#291 (0) { }

没有显示任何东西。

We're using Gearman and when do use methods like doLowBackground or doHigh, these all return a jobHandle, but when we do tasks there is no jobHandle object. We get the GearmanTask object, instead of getting the jobHandle, we get string(0) ""

Any ideas what could cause this?

Thank you!

EDIT: Here is the code and additional info:

// $client = \GearmanClient; // servers added, all that jazz // $workload = 'string'; $arguments = array( 'handleJob', $workload ); $task = call_user_func_array(array($client, $method), $arguments); if ($task instanceof GearmanTask) { $handles[] = $task->jobHandle(); } $data = $client->runTasks();

The tasks run correctly but $handle is being populated with empty strings (one for each task added)

EDIT: This is the response we get:

object(GearmanTask)#294 (0) { }

I've dumped every PECL gearman object, nothing ever displays, here's the client, populated with servers, options, etc

object(GearmanClient)#291 (0) { }

Doesn't show anything.

最满意答案

在任务被Gearman作业服务器接收并排队之前,作业句柄不会分配给任务。

但是,您可以使用GearmanClient :: setCreatedCallback()在排队后获取句柄。 必须在添加和运行任务之前完成此操作:

$client = new \GearmanClient(); $client->addServer('127.0.0.1'); $handles = array(); $client->setCreatedCallback(function (\GearmanTask $task) use (&$handles) { $handles[] = $task->jobHandle(); }); $client->addTask('functionName', 'workload'); // ... $client->runTasks();

A job handle is not assigned to a task until the task is received and queued by the Gearman job server.

However, you can use GearmanClient::setCreatedCallback() to get the handle once it has been queued. This must be done before both adding and running the tasks:

$client = new \GearmanClient(); $client->addServer('127.0.0.1'); $handles = array(); $client->setCreatedCallback(function (\GearmanTask $task) use (&$handles) { $handles[] = $task->jobHandle(); }); $client->addTask('functionName', 'workload'); // ... $client->runTasks();

更多推荐

本文发布于:2023-07-29 20:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1319525.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Gearman   PHP   jobHandle   returning   tasks

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!