Exemplo n.º 1
0
 /**
  * Build a worker pipe.
  *
  * @param   mixed   $workerId    Worker ID or a socket client (i.e. a
  *                               \Hoa\Socket\Client object).
  * @return  void
  * @throws  \Hoa\Worker\Exception
  */
 public function __construct($workerId)
 {
     if (is_string($workerId)) {
         $wid = Run::get($workerId);
         $this->_client = new Socket\Client($wid['socket']);
         return;
     } elseif ($workerId instanceof Socket\Client) {
         $this->_client = $workerId;
         return;
     }
     throw new Exception('Either you give a worker ID or you give an object of type ' . '\\Hoa\\Socket\\Client, but not anything else; given %s', 0, is_object($workerId) ? get_class($workerId) : $workerId);
     return;
 }
Exemplo n.º 2
0
 /**
  * Construct a worker.
  *
  * @param   mixed   $workerId    Worker ID or a socket client (i.e. a
  *                               \Hoa\Socket\Client object).
  * @param   string  $password    Worker's password.
  * @return  void
  * @throws  \Hoa\Worker\Exception
  * @throws  \Hoa\Worker\Backend\Exception
  */
 public function __construct($workerId, $password)
 {
     if (!is_string($workerId) && !$workerId instanceof Socket\Client) {
         throw new Exception('Either you give a worker ID or you give an object of type ' . '\\Hoa\\Socket\\Client, but not anything else; given %s', 0, is_object($workerId) ? get_class($workerId) : $workerId);
     }
     if (is_string($workerId)) {
         $this->_wid = $workerId;
         $handle = Worker\Run::get($workerId);
         $workerId = $handle['socket'];
     }
     set_time_limit(0);
     $this->_socket = $workerId;
     $this->setListener(new Event\Listener($this, ['message']));
     $this->_password = sha1($password);
     $this->_startTime = microtime(true);
     return;
 }