Exemplo n.º 1
0
 public function connect()
 {
     $socket = new EventSocket($this->context(), $this->options['socket_type']);
     foreach ($this->options['socket_options'] as $key => $value) {
         $socket->setSockOpt($key, $value);
     }
     foreach ((array) $this->options['bind'] as $dsn) {
         $socket->bind($dsn);
         if (substr($dsn, 0, 3) == 'ipc') {
             chmod(str_replace('ipc://', '', $dsn), 0777);
         }
     }
     foreach ((array) $this->options['connect'] as $dsn) {
         $socket->connect($dsn);
     }
     foreach ((array) $this->options['subscribe'] as $address) {
         $socket->setSockOpt(\ZMQ::SOCKOPT_SUBSCRIBE, $address);
     }
     $socket->confirmed($this->options['confirmed']);
     return $this->socket = $socket;
 }
Exemplo n.º 2
0
 /**
  * @param int $type
  * @return EventSocket
  */
 public function socket($type = null)
 {
     $socket = new EventSocket(new \ZMQContext(1, false), $type ?: \ZMQ::SOCKET_DEALER);
     $socket->setSockOpt(\ZMQ::SOCKOPT_LINGER, 1000)->setSockOpt(\ZMQ::SOCKOPT_SNDTIMEO, 1000)->setSockOpt(\ZMQ::SOCKOPT_RCVTIMEO, 1000);
     return $socket;
 }