我们正在使用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();更多推荐
发布评论