3

iam a newbie to php-gearman and with the help of some usefull tutorials, i tried out some examples. Like the above basic code.

Client Side

<?php
# Create our client object.
$client= new GearmanClient();

# Add default server (localhost).
$client->addServer("localhost", 4730);

echo "Sending job\n";

# Send reverse job
$result = $client->doBackground("reverse", "Hello!");
$stat = $client->jobStatus($result);
$done = false;

$client->setWorkloadCallback('test');

function test($data)
{
        echo $data;
}

while(!$done)
{
        if(!$stat[0])
        {
                $done = true;
                echo $result;
        }
        echo "status".json_encode($stat)."/n";
        $stat = $client->jobStatus($result);
}
?>

Server Side

<?php
# Create our worker object.
$worker= new GearmanWorker();

# Add default server (localhost).
$worker->addServer("localhost", 4730);

# Register function "reverse" with the server.
$worker->addFunction("reverse", "reverse_fn");

while (1)
{
  print "Waiting for job...\n";

  $ret= $worker->work();
  if ($worker->returnCode() != GEARMAN_SUCCESS)
    break;
}

function reverse_fn($job)
{
  $workload= $job->workload();
  echo "Received job: " . $job->handle() . "\n";
  echo "Workload: $workload\n";
  $result= strrev($workload);
  echo "Result: $result\n";
  return $result;
}
?>

This code gets me job Status.

My question is, while using GermanClient::doBackground how to get returned data after successfull worker execution?

PRASANTH
  • 695
  • 3
  • 15
  • 33

1 Answers1

0

Though this thread is ancient, some could use some sort of database with the jobhandle as a column. You could then query for the jobhandle afterwards.

Jan
  • 42,290
  • 8
  • 54
  • 79