Exemple #1
0
 public function connect(Dog_Server $server, $blocking = 0)
 {
     $this->server = $server;
     if (false === ($this->context = @stream_context_create())) {
         return Dog_Log::error('Dog_IRC::connect() ERROR: stream_context_create()');
     }
     $url = $server->getURL();
     if (false === ($socket = @stream_socket_client($url, $errno, $errstr, $server->getTimeout(), STREAM_CLIENT_CONNECT, $this->context))) {
         Dog_Log::error("Dog_IRC::connect() ERROR: stream_socket_client(): URL={$url} CONNECT_TIMEOUT=" . $server->getTimeout());
         return Dog_Log::error(sprintf('Dog_IRC::connect() $errno=%d; $errstr=%s', $errno, $errstr));
     }
     if ($server->isSSL()) {
         if (false === @stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
             return Dog_Log::error('Dog_IRC::connect() ERROR: stream_socket_enable_crypto(true, STREAM_CRYPTO_METHOD_TLS_CLIENT)');
         }
     }
     if (false === @stream_set_blocking($socket, 0)) {
         return Dog_Log::error('Dog_IRC::connect() ERROR: stream_set_blocking(): $blocked=0');
     }
     $this->timestamp = time();
     $this->socket = $socket;
     return true;
 }