PAMI\Client\Impl\ClientImpl::open PHP Метод

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

Opens a tcp connection to ami.
public open ( ) : void
Результат void
    public function open()
    {
        $cString = $this->scheme . $this->host . ':' . $this->port;
        $this->context = stream_context_create();
        $errno = 0;
        $errstr = '';
        $this->socket = @stream_socket_client($cString, $errno, $errstr, $this->cTimeout, STREAM_CLIENT_CONNECT, $this->context);
        if ($this->socket === false) {
            throw new ClientException('Error connecting to ami: ' . $errstr);
        }
        $msg = new LoginAction($this->user, $this->pass, $this->eventMask);
        $asteriskId = @stream_get_line($this->socket, 1024, Message::EOL);
        if (strstr($asteriskId, 'Asterisk') === false) {
            throw new ClientException("Unknown peer. Is this an ami?: {$asteriskId}");
        }
        $response = $this->send($msg);
        if (!$response->isSuccess()) {
            throw new ClientException('Could not connect: ' . $response->getMessage());
        }
        @stream_set_blocking($this->socket, 0);
        $this->currentProcessingMessage = '';
        $this->logger->debug('Logged in successfully to ami.');
    }

Usage Example

Пример #1
0
 /**
  * Connect to the Asterisk Manager Interface.
  *
  * @throws \PAMI\Client\Exception\ClientException
  *
  * @return $this
  */
 public function connect()
 {
     $results = $this->getEventManager()->trigger(__FUNCTION__ . '.pre', $this);
     if ($results->stopped()) {
         return $this;
     }
     $this->connection->open();
     $this->getEventManager()->trigger(__FUNCTION__ . '.post', $this);
     return $this;
 }
All Usage Examples Of PAMI\Client\Impl\ClientImpl::open