@param $server

@return \AMQPConnection
484525
private function _setupConnection($server)
    {
        $connectionData = [
            'host'            => $server[self::SERVER_HOST],
            'port'            => $server[self::SERVER_PORT],
            'read_timeout'    => 30,
            'write_timeout'   => 20,
            'connect_timeout' => 3,
            //     *      'login' => amqp.login The login name to use. Note: Max 128 characters.
            //     *      'password' => amqp.password Password. Note: Max 128 characters.
        ];
            
        $connection = new \AMQPConnection($connectionData);
        
        try {
            $connection->connect();
        } catch (\Exception $e) {
            Env::getLogger()->error($e->getMessage(), $connectionData);
            throw $e;
        }
        
        return $connection;
    }
1018845
public function createServerRequestFromArray(array $server)
    {
        return new ServerRequest(
            $server['REQUEST_METHOD'] ?? 'GET', 
            $server['REQUEST_URI'], 
            $this->getHeadersFromServerArr($server),
            null,
            $server['SERVER_PROTOCOL'] ?? 'HTTP/1.1',
            $server
        );
    }
651125
public function isServerAvailable($server)
    {
        $result = $this->tcp->connect($server, $this->config->getPort(), $this->config->getConnectTimeout());
        if ($result) {
            $this->tcp->close();
        }

        return $result;
    }
325008
public function server(string $key = null, $default = null)
    {
        if (is_null($key)) {
            return $this->getServerParams();
        }
        return $this->getServerParams()[$key] ?? $default;
    }
177423
public static function fromArray(array $server)
    {
        $uri = new self('');

        if (isset($server['HTTPS'])) {
            $uri->scheme = $server['HTTPS'] === 'on' ? 'https' : 'http';
        }

        [$host, $port] = Helpers::getHostAndPortFromArray($server);

        $uri->host = \strtolower($host);
        $uri->port = $uri->filterPort($port);

        $path = Helpers::getRequestUri($server);

        $fragment = '';
        if (\strpos($path, '#') !== false) {
            [$path, $fragment] = \explode('#', $path, 2);
        }

        $uri->path = $uri->filterPath(\explode('?', $path, 2)[0]);
        $uri->fragment = $uri->filterFragment($fragment);

        if (isset($server['QUERY_STRING'])) {
            $uri->query = $uri->filterQuery($server['QUERY_STRING']);
        }

        return $uri;
    }
1103881
public function createServerRequestFromArray(array $server){
        $method     = $server["REQUEST_METHOD"] ?? "GET";

        return new ServerRequest(
            $method,
            (new UriFactory())->createFromServer($server),
            $server,
            self::getUploadedFiles($_FILES),
            $_COOKIE,
            $_GET,
            self::getProtocolVersion($server)
        );
    }
1366888
public function setConnection($connection)
    {
        $this->connection = $connection;
        $this->database = DB::connection($this->connection);
        return $this;
    }
135747
protected function connect()
    {
        if (!$this->object) {
            $this->object = new \Memcache;
        }
        foreach ($this->servers as $server) {
            call_user_func_array(array($this->object, 'addServer'), $server);
        }
    }
268648
public function connect( array $servers )
	{
		$memcached = $this->getMemcached();

		// 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 )
			$memcached->addServer( $server['host'], $server['port'], $server['weight'] );

		$memcachedStatus = $memcached->getVersion();

		if ( !is_array( $memcachedStatus ) )
			throw new RuntimeException( 'No Memcached servers added.' );

		if ( in_array( '255.255.255', $memcachedStatus ) && count( array_unique( $memcachedStatus ) ) === 1 )
			throw new RuntimeException( 'Could not establish Memcached connection.' );

		return $memcached;
	}
998722
public function connect()
    {
        $sock = new Swoole\Coroutine\Client(SWOOLE_SOCK_TCP);
        if (!$sock->connect($this->host, $this->port, $this->connection_timeout))
        {
            throw new AMQPRuntimeException(
                sprintf(
                    'Error Connecting to server(%s): %s ',
                    $sock->errCode,
                    swoole_strerror($sock->errCode)
                ),
                $sock->errCode
            );
        }
        $this->sock = $sock;
    }
377135
public function setServer($server)
    {
        if ($this->_immutable) {

            throw new Zend_Http_UserAgent_Exception(
                'The User-Agent device object has already been retrieved; the server array is now immutable'
            );
        }

        if (!is_array($server) && !$server instanceof Traversable) {

            throw new Zend_Http_UserAgent_Exception(sprintf(
                'Expected an array or object implementing Traversable; received %s',
                (is_object($server) ? get_class($server) : gettype($server))
            ));
        }

        // Get an array if we don't have one
        if ($server instanceof ArrayObject) {
            $server = $server->getArrayCopy();
        } elseif ($server instanceof Traversable) {
            $tmp = array();
            foreach ($server as $key => $value) {
                $tmp[$key] = $value;
            }
            $server = $tmp;
            unset($tmp);
        }

        // Normalize key case
        $server = array_change_key_case($server, CASE_LOWER);

        $this->_server = $server;
        return $this;
    }
1206267
public function connect()
    {
        /*
         The Server MUST process a second CONNECT Packet sent from a Client as a protocol violation
         and disconnect the Client [MQTT-3.1.0-2]

         So CONNECT SHOULD be a blocking connection.
         */
        $this->socket->connect(function ($cli) {
            Debug::Log(Debug::INFO, 'connect(): Connection established.');
            /**
             * @var Message\CONNECT $connectobj
             */
            $connectobj = $this->getMessageObject(Message::CONNECT);

            if (!$this->connect_clean && empty($this->clientid)) {
                throw new Exception('Client id must be provided if Clean Session flag is set false.');
            }

            # default client id
            if (empty($this->clientid)) {
                $this->clientid = 'mqtt' . substr(md5(uniqid('mqtt', true)), 8, 16);
            } else {
                $connectobj->setClientId($this->clientid);
            }
            Debug::Log(Debug::DEBUG, 'connect(): clientid=' . $this->clientid);

            $connectobj->setKeepalive($this->keepalive);
            Debug::Log(Debug::DEBUG, 'connect(): keepalive=' . $this->keepalive);

            $connectobj->setAuth($this->username, $this->password);
            Debug::Log(Debug::DEBUG, 'connect(): username=' . $this->username . ' password=' . $this->password);

            $connectobj->setClean($this->connect_clean);

            if ($this->connect_will instanceof Will) {
                $connectobj->setWill($this->connect_will);
            }

            $length = 0;

            $bytes_written = $this->message_write($connectobj, $length);
            Debug::Log(Debug::DEBUG, 'connect(): bytes written=' . $bytes_written);

            $this->keepalive_time = swoole_timer_tick($this->keepalive * 500, [$this, 'keepalive']);
        }, [$this, 'onReceive'],function (){
            secho("MQTT", "连接mqtt服务器失败,正在重试");
            swoole_timer_after(1000,[$this,'connect']);
        },function (){
            if ($this->keepalive_time!=null) {
                swoole_timer_clear($this->keepalive_time);
                $this->keepalive_time = null;
            }
            $this->connect();
        });
    }
924038
public static function call(Server $server, $input)
    {
        $message = self::readMessage($input);

        if ($message === null) {
            return null;
        }

        /**
         * @var string
         */
        $method = $message->method;
        /**
         * @var \stdClass
         */
        $params = $message->params;

        $result = $server->call($method, $params);

        $response = new FromObject();
        $response->appendJson('result', $result);

        return self::createMessage($response->get());
    }
94386
public function connectToServers()
    {
        //Array for the list of server(s) to connect
        $addServers  = [];
        
        //Get all server already connected (persistent)
        $serversList = $this->obtainConnectedServerList();
        
        //Loop on server declared into config
        foreach ($this->config['servers'] as $server) {
            $this->completeServerInfos($server);
            
            $host   = $server['host'];
            $port   = $server['port'];
            $weight = $server['weight'];
            
            //not check if port = (int) 0; Doc said to define to 0 for socket.
            if (empty($host) || $port === null) {
                continue;
            }
            
            //search if the reading server is not already connected
            if (in_array($host.':'.$port, $serversList)) {
                continue;
            }
            
            \BFW\Application::getInstance()
                ->getMonolog()
                ->getLogger()
                ->debug(
                    'Try to connect to memcached server.',
                    [
                        'host' => $host,
                        'port' => $port
                    ]
                );
            
            //If not, add the server at the list to connect
            $addServers[] = [$host, $port, $weight];
        }

        //Connect to server(s)
        $this->addServers($addServers);
        
        //Check if connect is successfull
        $this->testConnect();
    }
361781
public function setCurrentConnection($connection = null, $server = null)
    {
        $connectionKey = $connection instanceof ConnectionKey ? $connection : $this->credentials->createConnectionKey($connection, $server);
        if ($this->current === $connectionKey->toHandle()) {
            return;
        }

        $this->current = $connectionKey->toHandle();
        $this->available = $this->getConnections()->map(function (ConnectionInterface $connection) use ($connectionKey) {
            $isCurrent = $connectionKey->is($connection->getConnectionKey());
            $connection->setCurrent($isCurrent);

            return $connection;
        });

        // Update events
        $this->bootstrapper->bootstrapUserCode();
    }
321456
protected static function connect(array $servers, $memcache = null)
    {
        if (!$memcache) {
            $memcache = new \Memcached();
        }

        foreach ($servers as $server) {
            $memcache->addServer($server['host'], $server['port'], $server['weight']);
        }

        if ($memcache->getVersion() === false) {
            throw new \RuntimeException('could not establish memcached connection!');
        }

        return $memcache;
    }
851892
public function connect($server = null)
    {

        if (empty($server)) {
            $server = $this->query['server'];
        }

        /** @TODO Throw an exception here */
        if (empty($server)) {
            return false;
        }

        $port = $this->query['server_port'];

        $parsed = $this->parseServer($server);
        $server = $parsed['host'];

        if (array_key_exists('port', $parsed)) {
            $port = $parsed['port'];
        }

        // Enter connection attempt loop
        $retry = 0;

        while ($retry <= $this->retry) {
            // Set query status
            $this->query['status'] = 'ready';

            // Connect to whois port
            $ptr = @fsockopen($server, $port, $errno, $errstr, $this->stimeout);

            if ($ptr > 0) {
                $this->query['status'] = 'ok';
                return $ptr;
            }

            // Failed this attempt
            $this->query['status'] = 'error';
            $this->query['error'][] = $errstr;
            $retry++;

            // Sleep before retrying
            sleep($this->sleep);
        }

        // If we get this far, it hasn't worked
        return false;
    }