Пример #1
0
 public function init()
 {
     // Only use gearman implementation when WP_GEARS is defined and true
     if (!defined('WP_GEARS') || !WP_GEARS) {
         return false;
     }
     global $gearman_servers;
     if (!class_exists('GearmanClient') || !class_exists('GearmanWorker')) {
         return false;
     }
     if (defined('DOING_ASYNC') && DOING_ASYNC) {
         $this->_worker = new GearmanWorker();
         $this->_client = new GearmanClient();
         if (empty($gearman_servers)) {
             $this->_client->addServer();
             return $this->_worker->addServer();
         } else {
             $this->_client->addServers(implode(',', $gearman_servers));
             return $this->_worker->addServers(implode(',', $gearman_servers));
         }
     } else {
         $this->_client = new GearmanClient();
         if (empty($gearman_servers)) {
             $this->_client->addServer();
         } else {
             $this->_client->addServers(implode(',', $gearman_servers));
         }
         // Supressing errors, because this will return true or false, depending on if we could connect & communicate
         return @$this->_client->ping('test');
     }
 }
Пример #2
0
 /**
  * enqueue
  *
  * @param string $value
  * @return boolean
  */
 public function enqueue($value)
 {
     $gm = new \GearmanClient();
     $gm->addServer($this->host, $this->port);
     $gm->queue_name = $this->queue_name;
     if ($gm->ping('ping')) {
         $job_handle = $gmclient->doBackground($this->queue_name, json_encode($value), md5($value));
         return $this->gmclient->returnCode() != GEARMAN_SUCCESS ? false : true;
     } else {
         return false;
     }
 }
Пример #3
0
 /**
  * @return \GearmanClient
  * @throws MQException
  */
 protected function client()
 {
     $client = new \GearmanClient();
     $client->addServers($this->dns);
     if (($haveGoodServer = $client->ping($this->id)) === false) {
         throw new MQException("Server does not access: {$this->dns}");
     }
     return $client;
 }