Beispiel #1
0
 public function client()
 {
     $config = $this->config->item('base_config');
     $host = $config['gearman']['host'];
     $port = $config['gearman']['port'];
     $client = new GearmanClient();
     $client->addServer($host, $port);
     $data = array('method' => 'get', 'url' => 'http://master.500mi.com/main/gearman/test', 'params' => array('wd' => '哈哈'));
     $job_handle = $client->doBackground("send_request", json_encode($data));
     if ($client->returnCode() != GEARMAN_SUCCESS) {
         echo "bad return code\n";
         exit;
     }
     $done = false;
     do {
         sleep(1);
         $stat = $client->jobStatus($job_handle);
         var_dump($stat);
         if (!$stat[0]) {
             $done = true;
         }
         echo "Running: " . ($stat[1] ? "true" : "false") . ", numerator: " . $stat[2] . ", denomintor: " . $stat[3] . "\n";
     } while (!$done);
     echo "done!\n";
 }
Beispiel #2
0
<?php

$client = new GearmanClient();
$client->addServer();
$job_handle = $client->doBackground("setup", 1);
var_dump($job_handle);
if ($client->returnCode() != GEARMAN_SUCCESS) {
    echo "bad return code\n";
    exit;
}
$done = false;
do {
    sleep(3);
    $stat = $client->jobStatus($job_handle);
    if (!$stat[0]) {
        // the job is known so it is not done
        $done = true;
    }
    echo "Running: " . ($stat[1] ? "true" : "false") . ", numerator: " . $stat[2] . ", denomintor: " . $stat[3] . "\n";
} while (!$done);
echo "done!\n";
 public function jobStatus($jobHanle)
 {
     return $this->_gearmanClient->jobStatus($jobHanle);
 }
Beispiel #4
0
<?php

$c = new GearmanClient();
$c->addServer('127.0.0.1');
$h = $c->doBackground('abc', 'abc');
//while(true)
var_dump($c->jobStatus($h));
//exit;
$w = new GearmanWorker();
$w->addServer('127.0.0.1');
var_dump($w->addFunction('abc', function () {
    echo "123\n";
}, $ctx, 0));
while (true) {
    $w->work();
}
Beispiel #5
0
 /**
  * 
  * @param handle $job_handle
  * @return array
  */
 public function jobStatus($job_handle)
 {
     return $this->gearmanClient->jobStatus($job_handle);
 }
Beispiel #6
0
 /**
  * Returns the Gearman job status for any task or all tasks
  * 
  *     // Get the status of all tasks
  *     $statuses = $request
  *
  * @param   GearmanTask  task to return status for (optional)
  * @return  array
  */
 public function status(GearmanTask $task = NULL)
 {
     if ($task !== NULL) {
         return $this->_gearman_client->jobStatus($task->jobHandle());
     } else {
         $status = array();
         foreach ($this->_task_handles as $uuid => $task) {
             $status[$uuid] = $this->_gearman_client->jobStatus($task->jobHandle());
         }
         return $status;
     }
 }