protected function setUri($uri) { parent::setUri($uri); $p = parse_url($uri); if ($p) { switch (strtolower($p['scheme'])) { case 'tcp': case 'tcp4': $this->type = SWOOLE_SOCK_TCP; $this->host = $p['host']; $this->port = $p['port']; break; case 'tcp6': $this->type = SWOOLE_SOCK_TCP6; $this->host = $p['host']; $this->port = $p['port']; break; case 'ssl': case 'sslv2': case 'sslv3': case 'tls': $this->type = SWOOLE_SOCK_TCP | SWOOLE_SSL; $this->host = $p['host']; $this->port = $p['port']; break; case 'unix': $this->type = SWOOLE_UNIX_STREAM; $this->host = $p['path']; $this->port = 0; break; default: throw new Exception("Only support tcp, tcp4, tcp6 or unix scheme"); } if (($this->type === SWOOLE_SOCK_TCP || $this->type === SWOOLE_SOCK_TCP | SWOOLE_SSL) && filter_var($this->host, FILTER_VALIDATE_IP) === false) { $ip = gethostbyname($this->host); if ($ip === $this->host) { throw new Exception('DNS lookup failed'); } else { $this->host = $ip; } } $this->close(); } else { throw new Exception("Can't parse this uri: " . $uri); } }
protected function setUri($uri) { parent::setUri($uri); $p = parse_url($uri); if ($p) { switch (strtolower($p['scheme'])) { case 'ws': $this->host = $p['host']; $this->port = isset($p['port']) ? $p['port'] : 80; $this->path = isset($p['path']) ? $p['path'] : '/'; $this->ssl = false; break; case 'wss': $this->host = $p['host']; $this->port = isset($p['port']) ? $p['port'] : 443; $this->path = isset($p['path']) ? $p['path'] : '/'; $this->ssl = true; break; default: throw new Exception("Only support ws and wss scheme"); } } else { throw new Exception("Can't parse this uri: " . $uri); } $this->header['Host'] = $this->host; $this->header['Connection'] = $this->keepAlive ? 'keep-alive' : 'close'; if ($this->keepAlive) { $this->header['Keep-Ailve'] = $this->keepAliveTimeout; } if (filter_var($this->host, FILTER_VALIDATE_IP) === false) { $ip = gethostbyname($this->host); if ($ip === $this->host) { throw new Exception('DNS lookup failed'); } else { $this->ip = $ip; } } else { $this->ip = $this->host; } }
protected function setUri($uri) { parent::setUri($uri); $url = parse_url($uri); $this->secure = strtolower($url['scheme']) == 'https'; $this->host = strtolower($url['host']); $this->path = isset($url['path']) ? $url['path'] : "/"; $this->keepAlive = true; $this->keepAliveTimeout = 300; }