Kafka\Socket::connect PHP Метод

connect() публичный Метод

Connects the socket
public connect ( ) : void
Результат void
    public function connect()
    {
        if (is_resource($this->stream)) {
            return;
        }
        if (empty($this->host)) {
            throw new \Kafka\Exception('Cannot open null host.');
        }
        if ($this->port <= 0) {
            throw new \Kafka\Exception('Cannot open without port.');
        }
        $this->stream = @fsockopen($this->host, $this->port, $errno, $errstr, $this->sendTimeoutSec + $this->sendTimeoutUsec / 1000000);
        if ($this->stream == false) {
            $error = 'Could not connect to ' . $this->host . ':' . $this->port . ' (' . $errstr . ' [' . $errno . '])';
            throw new \Kafka\Exception\SocketConnect($error);
        }
        stream_set_blocking($this->stream, 0);
    }

Usage Example

Пример #1
0
 /**
  * Connect to Kafka via socket
  *
  * @return void
  */
 public function connect()
 {
     if (null === $this->socket) {
         $this->socket = new Socket($this->host, $this->port, $this->recvTimeoutSec, $this->recvTimeoutUsec, $this->sendTimeoutSec, $this->sendTimeoutUsec);
     }
     $this->socket->connect();
 }