Connect to the host on the port defined for this TCP socket.

@param string $host
@param int $port
@param int $timeout
@return bool
481653
public function connect($host, $port, $timeout = 1)
    {
        $this->socket = @stream_socket_client(
            "tcp://$host:$port",
            $errorNumber,
            $errorMessage,
            $timeout,
            STREAM_CLIENT_CONNECT,
            stream_context_create($this->options)
        );

        return (bool) $this->socket;
    }
457324
public function connect($timeout = 0.5)
    {
        if (extension_loaded('swoole'))
        {
            $type = preg_match('/^[0-9\.]+$/', $this->host) ? SWOOLE_SOCK_TCP : SWOOLE_SOCK_UNIX_STREAM;
            if ($this->ssl)
            {
                $type |= SWOOLE_SSL;
            }
            $this->socket = new \swoole_client($type);
            if ($this->ssl_key_file)
            {
                $this->socket->set(array(
                    'ssl_key_file' => $this->ssl_key_file,
                    'ssl_cert_file' => $this->ssl_cert_file
                ));
            }
        }
        else
        {
            $this->socket = new TCP;
        }
        //建立连接
        if (!$this->socket->connect($this->host, $this->port, $timeout))
        {
            return false;
        }
        $this->connected = true;
        //WebSocket握手
        if ($this->socket->send($this->createHeader()) === false)
        {
            return false;
        }
        $headerBuffer = '';
        while(true)
        {
            $_tmp = $this->socket->recv();
            if ($_tmp)
            {
                $headerBuffer .= $_tmp;
                $offset = stripos($headerBuffer,"\r\n\r\n");
                if ($offset === false) {
                    continue;
                }
                $header = substr($headerBuffer, 0, $offset+4);
                $this->buffer = substr($headerBuffer, $offset+4);
            }
            else
            {
                return false;
            }
            return $this->doHandShake($header);
        }
        return false;
    }
1067573
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->options->getStreamContext());
        $this->setStreamTimeout($timeout);

        $infoResponse = $this->receive();

        if ($this->isErrorResponse($infoResponse) === true) {
            throw Exception::forFailedConnection($infoResponse);
        } else {
            $this->processServerInfo($infoResponse);
            if ($this->serverInfo->isTLSRequired()) {
                set_error_handler(
                    function ($errno, $errstr, $errfile, $errline) {
                        restore_error_handler();
                        throw Exception::forFailedConnection($errstr);
                    });

                if (!stream_socket_enable_crypto(
                        $this->streamSocket, true, STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT)) {
                    throw Exception::forFailedConnection('Error negotiating crypto');
                }

                restore_error_handler();
            }
        }

        $msg = 'CONNECT '.$this->options;
        $this->send($msg);
        $this->ping();
        $pingResponse = $this->receive();

        if ($this->isErrorResponse($pingResponse) === true) {
            throw Exception::forFailedPing($pingResponse);
        }
    }
838296
protected function connect($host)
        {
            $remote_socket = $host . ':' . $this->connect_port;
            $errnum = 0;
            $errstr = '';
            $this->host = $remote_socket;
            // open connection
            $this->debug('Connecting to ' . $this->host);
            $this->socket = @stream_socket_client(
                $this->host,
                $errnum,
                $errstr,
                $this->connect_timeout,
                STREAM_CLIENT_CONNECT,
                stream_context_create(array())
            );
            // connected?
            if (!$this->connected()) {
                $this->debug('Connect failed: ' . $errstr . ', error number: ' . $errnum . ', host: ' . $this->host);
                throw new Exception('Cannot ' .
                'open a connection to remote host (' . $this->host . ')');
            }
            $result = stream_set_timeout($this->socket, $this->connect_timeout);
            if (!$result) {
                throw new Exception('Cannot set timeout');
            }
            $this->debug('Connected to ' . $this->host . ' successfully');
        }
58666
public function connect($host, $port, Connection $connection, $timeout = 5)
    {
        if ($this->isConnected || $this->isConnecting) {
            return new RejectedPromise(new \LogicException('The client is already connected.'));
        }

        $this->isConnecting = true;
        $this->isConnected = false;

        $this->host = $host;
        $this->port = $port;

        $deferred = new Deferred();

        $this->establishConnection($this->host, $this->port, $timeout)
            ->then(function (DuplexStreamInterface $stream) use ($connection, $deferred, $timeout) {
                $this->stream = $stream;

                $this->emit('open', [$connection, $this]);

                $this->registerClient($connection, $timeout)
                    ->then(function (ConnectResponsePacket $responsePacket) use ($deferred, $connection) {
                        $this->isConnecting = false;
                        $this->isConnected = true;
                        $this->connection = $connection;

                        $this->emit('connect', [$responsePacket, $this]);
                        $deferred->resolve($responsePacket);
                    })
                    ->otherwise(function (\Exception $e) use ($deferred, $connection) {
                        $this->isConnecting = false;

                        $this->emitError($e);
                        $deferred->reject($e);

                        if ($this->stream !== null) {
                            $this->stream->close();
                        }

                        $this->emit('close', [$connection, $this]);
                    });
            })
            ->otherwise(function (\Exception $e) use ($deferred) {
                $this->isConnecting = false;

                $this->emitError($e);
                $deferred->reject($e);
            });

        return $deferred->promise();
    }
496231
public function connect($host = '127.0.0.1', $port = 21)
	{
		$errno = null;
		$err   = null;

		// If already connected, return
		if (\is_resource($this->conn))
		{
			return true;
		}

		// If native FTP support is enabled let's use it...
		if (FTP_NATIVE)
		{
			$this->conn = @ftp_connect($host, $port, $this->timeout);

			if ($this->conn === false)
			{
				throw new FilesystemException(sprintf('%1$s: Could not connect to host " %2$s " on port " %3$s "', __METHOD__, $host, $port));
			}

			// Set the timeout for this connection
			ftp_set_option($this->conn, FTP_TIMEOUT_SEC, $this->timeout);

			return true;
		}

		// Connect to the FTP server.
		$this->conn = @ fsockopen($host, $port, $errno, $err, $this->timeout);

		if (!$this->conn)
		{
			throw new FilesystemException(
				sprintf(
					'%1$s: Could not connect to host " %2$s " on port " %3$s ". Socket error number: %4$s and error message: %5$s',
					__METHOD__,
					$host,
					$port,
					$errno,
					$err
				)
			);
		}

		// Set the timeout for this connection
		socket_set_timeout($this->conn, $this->timeout, 0);

		// Check for welcome response code
		if (!$this->_verifyResponse(220))
		{
			throw new FilesystemException(sprintf('%1$s: Bad response. Server response: %2$s [Expected: 220]', __METHOD__, $this->response));
		}

		return true;
	}
478560
public function Connect( $Address, $Port, $Timeout = 3, $Engine = self::SOURCE )
		{
			$this->Disconnect( );
			
			if( !is_int( $Timeout ) || $Timeout < 0 )
			{
				throw new InvalidArgumentException( 'Timeout must be an integer.', InvalidArgumentException::TIMEOUT_NOT_INTEGER );
			}
			
			$this->Socket->Open( $Address, (int)$Port, $Timeout, (int)$Engine );
			
			$this->Connected = true;
		}
781510
function checkPort(port, host, callback) {
    var socket = new Socket(),
        status = null;
    socket.on('connect', () => {
        status = 'open';
        socket.end();
    });
    socket.setTimeout(1500);
    socket.on('timeout', () => {
        status = 'closed';
        socket.destroy();
    });
    socket.on('error', (exception) => {
        status = 'closed';
    });
    socket.on('close', (exception) => {
        callback(null, status,host,port);
    });
    socket.connect(port, host);
}
1080044
public static function ping(string $host, int $port, int $timeout = 5): bool
    {
        if ($fp = @fsockopen($host, $port, $errCode, $errStr, $timeout)) {
            fclose($fp);
            return true;
        }
        return false;
    }
414306
public function connect($timeout = 5.0)
    {
        if (true === $this->isConnected()) {
            return false;
        }

        $errorNumber = 0;
        $errorMessage = '';

        $this->connection = @fsockopen(
            $this->parameters['host'],
            $this->parameters['port'],
            $errorNumber,
            $errorMessage,
            $timeout
        );

        if (false === $this->isConnected()) {
            throw new GearmanConnectionException($errorMessage, $errorNumber);
        }

        return true;
    }
1353473
public function connect($host, $ssl = false, $port = 21, $timeout = 90)
    {
        if ($ssl) {
            $this->conn = @$this->ftp->ssl_connect($host, $port, $timeout);
        } else {
            $this->conn = @$this->ftp->connect($host, $port, $timeout);
        }
        if (!$this->conn) {
            throw new FtpException('Unable to connect');
        }

        return $this;
    }
1223403
public function addRedisServer($host, $port = 6379, $db = 0, $timeout = 5, $auth = '') {
		$this->settings = [
			'host'    => $host,
			'port'    => $port,
			'db'      => $db,
			'timeout' => $timeout,
			'auth'    => $auth
		];
	}
1105915
public function connect($timeout = 90) {
        $host = $this->getAuthenticator()->getHost();
        $port = $this->getAuthenticator()->getPort();
        $this->setConnection(@ftp_connect($host, $port, $timeout));
        if (false === $this->getConnection()) {
            throw $this->newFTPException("connection failed");
        }
        return $this;
    }
831185
protected function getSocket($host, $port, $timeout)
    {
        return stream_socket_client("tcp://{$host}:{$port}", $error, $message, $timeout, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT);
    }
889591
private function establishConnection($host, $port, Connection $connection, $timeout)
    {
        $this->logger->info(sprintf('Connecting to %s:%d...', $host, $port));

        return $this->client->connect($host, $port, $connection, $timeout);
    }
694498
public function connect($timeout = 0.5)
    {
        if (!extension_loaded('swoole'))
        {
            throw new \Exception('swoole extension is required for WebSocketAsync');
        }

        //没有onMessage
        if (!$this->_callback('message'))
        {
            throw new \Exception('no message event callback.');
        }

        $type = SWOOLE_TCP;
        if ($this->ssl)
        {
            $type |= SWOOLE_SSL;
        }

        $this->socket = new \swoole_client($type, SWOOLE_SOCK_ASYNC);
        if ($this->ssl_key_file)
        {
            $this->socket->set(array(
                'ssl_key_file' => $this->ssl_key_file,
                'ssl_cert_file' => $this->ssl_cert_file
            ));
        }

        $this->socket->on("connect", array($this, 'onConnect'));
        $this->socket->on("receive", array($this, 'onReceive'));
        $this->socket->on("error", array($this, 'onError'));
        $this->socket->on("close", array($this, 'onClose'));

        $this->socket->connect($this->host, $this->port, $timeout);
    }
771726
public function fsockopen($hostname, $port = -1, &$errno = 0, &$errstr = '', $timeout = null)
    {
        $this->handle = fsockopen($hostname, $port, $errno, $errstr, (is_null($timeout) ? ini_get("default_socket_timeout") : $timeout));

        if ($this->handle != false && $errno === 0 && $errstr === '') {
            return $this->handle;
        }
        return false;
    }