Nats\ConnectionOptions::getAddress PHP Method

getAddress() public method

Get the URI for a server.
public getAddress ( ) : string
return string
    public function getAddress()
    {
        return "tcp://" . $this->host . ":" . $this->port;
    }

Usage Example

示例#1
0
 /**
  * Connect to server.
  *
  * @param float $timeout Number of seconds until the connect() system call should timeout.
  *
  * @throws \Exception Exception raised if connection fails.
  * @return void
  */
 public function connect($timeout = null)
 {
     if ($timeout === null) {
         $timeout = intval(ini_get('default_socket_timeout'));
     }
     $this->timeout = $timeout;
     $this->streamSocket = $this->getStream($this->options->getAddress(), $timeout);
     $this->setStreamTimeout($timeout);
     $msg = 'CONNECT ' . $this->options;
     $this->send($msg);
     $connect_response = $this->receive();
     if (strpos($connect_response, '-ERR') !== false) {
         throw new \Exception("Failing connection: {$connect_response}");
     }
     $this->ping();
     $ping_response = $this->receive();
     if ($ping_response !== "PONG") {
         if (strpos($ping_response, '-ERR') !== false) {
             throw new \Exception("Failing on first ping: {$ping_response}");
         }
     }
 }