/**
  * Adds into worker all defined Servers.
  * If any is defined, performs default method
  *
  * @param \GearmanWorker $gmworker Worker to perform configuration
  * @param array          $servers  Servers array
  *
  * @throws ServerConnectionException if a connection to a server was not possible.
  *
  * @return array         Successfully added servers
  */
 private function addServers(\GearmanWorker $gmworker, array $servers)
 {
     $successes = array();
     if (!empty($servers)) {
         foreach ($servers as $server) {
             //We need to use try/catch here to handle case when the server is down
             try {
                 //before addServer check if server is available
                 if (TCPHelper::tryConnection($server['host'], $server['port'])) {
                     if (@$gmworker->addServer($server['host'], $server['port'])) {
                         $successes[] = $server;
                     }
                 }
             } catch (\GearmanException $e) {
             }
         }
     } else {
         if (@$gmworker->addServer()) {
             $successes[] = array('127.0.0.1', 4730);
         }
     }
     return $successes;
 }
 /**
  * Given a GearmanClient, set all included servers
  *
  * @param \GearmanClient $gearmanClient Object to include servers
  *
  * @return GearmanClient Returns self object
  */
 protected function assignServers(\GearmanClient $gearmanClient)
 {
     $servers = $this->defaultServers;
     if (!empty($this->servers)) {
         $servers = $this->servers;
     }
     /**
      * We include each server into gearman client
      */
     foreach ($servers as $server) {
         //We need to use try/catch here to handle case when the server is down
         try {
             //before addServer check if server is available
             if (TCPHelper::tryConnection($server['host'], $server['port'])) {
                 $gearmanClient->addServer($server['host'], $server['port']);
             }
         } catch (\GearmanException $ex) {
             if ($this->logger) {
                 $this->logger->error('GearmanException adding ' . $server['host'] . ', ' . $server['port'] . ' server:' . $ex->getMessage());
             }
         }
     }
     $this->assignTimeout($gearmanClient);
     return $this;
 }