예제 #1
0
 private function init()
 {
     // Run on all gearman servers and collect data and accumalate it
     foreach ($this->hosts as $_server) {
         try {
             $gm = new GearmanHost($_server);
         } catch (Exception $ex) {
             continue;
         }
         $serverWorkers = $gm->getWorkers();
         $serverJobs = $gm->getJobs();
         if (!empty($this->orderFunction) && is_callable($this->orderFunction)) {
             $serverJobs = call_user_func($this->orderFunction, $serverJobs);
         }
         $this->serversJobs[$_server] = $serverJobs;
         $this->serversWorkers[$_server] = $serverWorkers;
         foreach ($serverJobs as $jobName => $job) {
             $total = $job[GearmanHost::WORKER_TOTAL];
             $running = $job[GearmanHost::WORKER_RUNNING];
             $available = $job[GearmanHost::WORKER_AVAILABLE];
             if (!isset($this->accumaltiveJobs[$jobName])) {
                 $this->accumaltiveJobs[$jobName][GearmanHost::WORKER_TOTAL] = 0;
                 $this->accumaltiveJobs[$jobName][GearmanHost::WORKER_RUNNING] = 0;
                 $this->accumaltiveJobs[$jobName][GearmanHost::WORKER_AVAILABLE] = 0;
             }
             $this->accumaltiveJobs[$jobName][GearmanHost::WORKER_TOTAL] += $total;
             $this->accumaltiveJobs[$jobName][GearmanHost::WORKER_RUNNING] += $running;
             $this->accumaltiveJobs[$jobName][GearmanHost::WORKER_AVAILABLE] = max($this->accumaltiveJobs[$jobName][GearmanHost::WORKER_AVAILABLE], $available);
         }
         foreach ($serverWorkers as $type => $worker) {
             $available = $worker[GearmanHost::WORKER_TOTAL];
             $running = $worker[GearmanHost::WORKER_RUNNING];
             $free = $worker[GearmanHost::WORKER_AVAILABLE];
             $queued = $worker[GearmanHost::WORKER_QUEUED];
             if (!isset($this->accumaltiveWorkers[$type])) {
                 $this->accumaltiveWorkers[$type][GearmanHost::WORKER_TOTAL] = 0;
                 $this->accumaltiveWorkers[$type][GearmanHost::WORKER_RUNNING] = 0;
                 $this->accumaltiveWorkers[$type][GearmanHost::WORKER_AVAILABLE] = 0;
                 $this->accumaltiveWorkers[$type][GearmanHost::WORKER_QUEUED] = 0;
             }
             $this->accumaltiveWorkers[$type][GearmanHost::WORKER_TOTAL] = max($available, $this->accumaltiveWorkers[$type][GearmanHost::WORKER_TOTAL]);
             $this->accumaltiveWorkers[$type][GearmanHost::WORKER_RUNNING] += $running;
             $this->accumaltiveWorkers[$type][GearmanHost::WORKER_QUEUED] += $queued;
         }
         foreach ($this->accumaltiveWorkers as $type => $worker) {
             $this->accumaltiveWorkers[$type][GearmanHost::WORKER_AVAILABLE] = $worker[GearmanHost::WORKER_TOTAL] - $worker[GearmanHost::WORKER_RUNNING];
         }
     }
 }
예제 #2
0
 public function getTotalWorkers()
 {
     $workers = $this->_gearmanHost->getWorkers();
     return $workers['other']['TOTAL'] == 0;
 }