문제

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.

도움이 되었습니까?

해결책

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();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top