Try to connect to given host.

@param array $host
@return resource (stream)
@throws ConnectionException if connection setup fails
321610
protected function connectSocket(array $host)
    {
        $this->activeHost = $host;
        $errNo = null;
        $errStr = null;

        $context = stream_context_create($this->context);
        $flags = STREAM_CLIENT_CONNECT;
        if ($this->persistentConnection) {
            $flags |= STREAM_CLIENT_PERSISTENT;
        }
        $socket = @stream_socket_client(
            $host['scheme'] . '://' . $host['host'] . ':' . $host['port'],
            $errNo,
            $errStr,
            $this->connectTimeout,
            $flags,
            $context
        );


        if (!is_resource($socket)) {
            throw new ConnectionException(sprintf('Failed to connect. (%s: %s)', $errNo, $errStr), $host);
        }

        if (!@stream_set_blocking($socket, false)) {
            throw new ConnectionException('Failed to set non blocking mode for stream.', $host);
        }
        $this->host = $host['host'];
        return $socket;
    }
64749
public function restrictHost($host) {
        if ( ! is_array($host)) {
            $host = [$host];
        }

        $this->getRoutesMatcher()->getRestrictionsMatcher()
            ->setHosts($host);

        return $this;
    }
1161105
public function connect(array $servers)
	{
		$memcache = $this->getEngine();

		// For each server in the array, we'll just extract the configuration and add
		// the server to the Memcached connection. Once we have added all of these
		// servers we'll verify the connection is successful and return it back.
		foreach ($servers as $server)
		{
			$memcache->addServer(
				$server['host'], $server['port'], $server['weight']
			);
		}

		if ($memcache->getVersion() === false)
		{
			throw new RuntimeException('Could not establish Memcached connection.');
		}

		// Memcahed has no list keys, we do our own accounting, initialise key index
		if ($memcache->get($this->options['hash'] . '-index') === false)
		{
			$empty = array();
			self::$_db->set($this->oprions['hash'] . '-index', $empty, $this->options['compress'], 0);
		}

		return $memcache;
	}
1291868
public function connect($host, $port = 80, $secure = false)
    {
        // If the URI should be accessed via SSL, prepend the Hostname with ssl://
        $host = ($secure ? $this->config['ssltransport'] : 'tcp') . '://' . $host;

        // If we are connected to the wrong host, disconnect first
        if (($this->connected_to[0] != $host || $this->connected_to[1] != $port)) {
            if (is_resource($this->socket)) { $this->close();
            }
        }

        // Now, if we are not connected, connect
        if (! is_resource($this->socket) || ! $this->config['keepalive']) {
            $context = stream_context_create();
            if ($secure) {
                if ($this->config['sslcert'] !== null) {
                    if (! stream_context_set_option(
                        $context, 'ssl', 'local_cert',
                        $this->config['sslcert']
                    )
                    ) {
                        include_once 'Zend/Http/Client/Adapter/Exception.php';
                        throw new Zend_Http_Client_Adapter_Exception('Unable to set sslcert option');
                    }
                }
                if ($this->config['sslpassphrase'] !== null) {
                    if (! stream_context_set_option(
                        $context, 'ssl', 'passphrase',
                        $this->config['sslpassphrase']
                    )
                    ) {
                        include_once 'Zend/Http/Client/Adapter/Exception.php';
                        throw new Zend_Http_Client_Adapter_Exception('Unable to set sslpassphrase option');
                    }
                }
            }

            $flags = STREAM_CLIENT_CONNECT;
            if ($this->config['persistent']) { $flags |= STREAM_CLIENT_PERSISTENT;
            }
            
            $this->socket = @stream_socket_client(
                $host . ':' . $port,
                $errno,
                $errstr,
                (int) $this->config['timeout'],
                $flags,
                $context
            );
            if (! $this->socket) {
                $this->close();
                include_once 'Zend/Http/Client/Adapter/Exception.php';
                throw new Zend_Http_Client_Adapter_Exception(
                    'Unable to Connect to ' . $host . ':' . $port . '. Error #' . $errno . ': ' . $errstr
                );
            }

            // Set the stream timeout
            if (! stream_set_timeout($this->socket, (int) $this->config['timeout'])) {
                include_once 'Zend/Http/Client/Adapter/Exception.php';
                throw new Zend_Http_Client_Adapter_Exception('Unable to set the connection timeout');
            }

            // Update connected_to
            $this->connected_to = array($host, $port);
        }
    }
318751
public final function withHost($host): UriInterface
   {
       if (!is_string($host) || !($parsedHost = $this->parseHost($host))) {
           throw new InvalidArgumentException(
               "Can't get with host: invalid host name");
       }
       return $this->with("host", $parsedHost);
   }
30795
public function connect($host = null, $port = null)
    {
        $this->_host = null !== $host ? $host : $this->_host;
        $this->_port = null !== $port ? $port : $this->_port;
        if (false === $this->_ssh_resource = ssh2_connect($this->_host, $this->_port)) {
            throw new TransportException(sprintf('Enable to connect to %s:%i.', $this->_host, $this->_port));
        }

        return $this;
    }
31783
public function make($host)
    {
        $host = $this->resolver->resolve($host, '/');
        $hash = md5($host);

        if (isset($this->instances[$hash])) {
            return $this->instances[$hash];
        }

        $validator = new Validator(
            $this->validator,
            new ResourceNormalizer
        );
        $instance = new Server(
            $this->capabilities->make($host),
            new Client(
                $this->loader->make($host),
                $this->serializer,
                $this->resolver,
                $validator,
                $this->dispatcher,
                $this->http
            )
        );
        $this->instances[$hash] = $instance;

        return $instance;
    }
304208
public function withHost(string $host): self
    {
        $newConstraints = $this->constraints;
        $newConstraints[self::CONSTRAINT_HOST] = $host;
        return new static($newConstraints);
    }
471355
public function connect($host, $port = 80, $secure = false)
    {
        // If no proxy is set, fall back to Socket adapter
        if (!$this->config['proxy_host']) {
            return parent::connect($host, $port, $secure);
        }

        /* Url might require stream context even if proxy connection doesn't */
        if ($secure) {
            $this->config['sslusecontext'] = true;
        }

        // Connect (a non-secure connection) to the proxy server
        return parent::connect(
            $this->config['proxy_host'],
            $this->config['proxy_port'],
            false
        );
    }
717934
public function connect( $host, $port = 21, $timeout = 10 )
	{
		$resource	= @ftp_connect( $host, $port, $timeout );
		if( !$resource )
			return FALSE;
		$this->host	= $host;
		$this->port	= $port;
		$this->resource	= $resource;
		return TRUE;
	}
864626
public function connect(array $servers)
	{
		$memcache = $this->getMemcache();

		// For each server in the array, we'll just extract the configuration and add
		// the server to the Memcached connection. Once we have added all of these
		// servers we'll verify the connection is successful and return it back.
		foreach ($servers as $server)
		{
			$memcache->addServer(
				$server['host'], $server['port'], $server['weight']
			);
		}

		if ($memcache->getVersion() === false)
		{
			throw new RuntimeException("Could not establish Memcache connection.");
		}

		return $memcache;
	}
717481
public static function connect($host = null, $database = null, $user = null, $password = null)
    {
        if (config('app.setup')) {
            self::$connection = new MysqlConnector($host, $database, $user, $password);
            self::$server = self::$connection->connector;
        }

        return self::$server;
    }
317037
public static function connect(string $host, int $port = 119, array $options = []): Generator
    {
        // Connect to the remote host.
        $socket = yield from Dns\connect($host, $port, $options);

        // Encoder for encoding and decoding the protocol.
        $encoder = new Rfc3977Encoder();

        // Create the client object.
        $client = new static($socket, $encoder);

        // The server should respond with a welcome message.
        $response = yield from $encoder->readResponse($socket);

        // A 201 response code means posting is not allowed.
        if ($response->code() === 201) {
            $client->postingAllowed = false;
        }

        // Get the server capabilities.
        yield from $client->getServerCapabilities();

        // Set reader client mode if necessary.
        if ($client->hasCapability('MODE-READER') || !$client->hasCapability('READER')) {
            yield from $client->sendCommand(new Command('MODE READER'));
        }

        // Enable encryption if supported.
        if ($client->hasCapability('STARTTLS')) {
            yield from $client->sendCommand(new Command('STARTTLS'));
            yield from $socket->enableCrypto(STREAM_CRYPTO_METHOD_ANY_CLIENT);
        }

        return $client;
    }
830879
public function connectTcp($host, $port)
    {
        $this->type = 'tcp';
        $pton = @inet_pton($host);
        $fd = null;
        if ($pton === false) { // dirty check
            \PHPDaemon\Clients\DNS\Pool::getInstance()->resolve($this->host, function ($result) use ($host, $port) {
                if (!$result) {
                    Daemon::log(get_class($this) . '->connectTcp : unable to resolve hostname: ' . $host);
                    $this->onStateEv($this->bev, \EventBufferEvent::ERROR);
                    return;
                }
                // @todo stack of addrs
                if (is_array($result)) {
                    if (!sizeof($result)) {
                        return;
                    }
                    srand(Daemon::$process->getPid());
                    $real = $result[rand(0, sizeof($result) - 1)];
                    srand();
                } else {
                    $real = $result;
                }
                $this->connectTcp($real, $port);
            });
            return true;
        }
        $this->hostReal = $host;
        if ($this->host === null) {
            $this->host = $this->hostReal;
        }
        // TCP
        $l = mb_orig_strlen($pton);
        if ($l === 4) {
            $this->addr = $host . ':' . $port;
            if (!$this->bevConnectEnabled) {
                $fd = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
            }
        } elseif ($l === 16) {
            $this->addr = '[' . $host . ']:' . $port;
            if (!$this->bevConnectEnabled) {
                $fd = socket_create(AF_INET6, SOCK_STREAM, SOL_TCP);
            }
        } else {
            return false;
        }
        if (!$this->bevConnectEnabled && !$fd) {
            return false;
        }
        if (!$this->bevConnectEnabled) {
            socket_set_nonblock($fd);
        }
        if (!$this->bevConnectEnabled) {
            $this->fd = $fd;
            $this->setTimeouts(
                $this->timeoutRead !== null ? $this->timeoutRead : $this->timeout,
                $this->timeoutWrite !== null ? $this->timeoutWrite : $this->timeout
            );
            socket_connect($fd, $host, $port);
            socket_getsockname($fd, $this->locAddr, $this->locPort);
        } else {
            $this->bevConnect = true;
        }
        $this->setFd($fd);
        if (!$this->bev) {
            return false;
        }
        return true;
    }
411479
public function setHost($host)
    {
        if ($this->validateHost($host) === false) {
            throw new Zend_Uri_Exception("Host \"$host\" is not a valid HTTP host");
        }

        $oldHost     = $this->_host;
        $this->_host = $host;

        return $oldHost;
    }
1180852
private function establishConnection($host, $port, $timeout)
    {
        $deferred = new Deferred();

        $timer = $this->loop->addTimer(
            $timeout,
            function () use ($deferred, $timeout) {
                $exception = new \RuntimeException(sprintf('Connection timed out after %d seconds.', $timeout));
                $deferred->reject($exception);
            }
        );

        $this->connector->connect($host.':'.$port)
            ->always(function () use ($timer) {
                $this->loop->cancelTimer($timer);
            })
            ->then(function (DuplexStreamInterface $stream) use ($deferred) {
                $stream->on('data', function ($data) {
                    $this->handleReceive($data);
                });

                $stream->on('close', function () {
                    $this->handleClose();
                });

                $stream->on('error', function (\Exception $e) {
                    $this->handleError($e);
                });

                $deferred->resolve($stream);
            })
            ->otherwise(function (\Exception $e) use ($deferred) {
                $deferred->reject($e);
            });

        return $deferred->promise();
    }
1037093
public function assertHostIs($host)
    {
        $pattern = str_replace('\*', '.*', preg_quote($host, '/'));

        $actual = parse_url($this->driver->getCurrentURL(), PHP_URL_HOST) ?? '';

        PHPUnit::assertRegExp(
            '/^'.$pattern.'$/u', $actual,
            "Actual host [{$actual}] does not equal expected host [{$pattern}]."
        );

        return $this;
    }