MongoClient::connectToHost PHP 메소드

connectToHost() 개인적인 메소드

Establish a connection to specified host if not already connected to it
private connectToHost ( $host, $port ) : Mongofill\Protocol
$host
$port
리턴 Mongofill\Protocol - The protocol for the given connection parameters
    private function connectToHost($host, $port)
    {
        $host_key = "{$host}:{$port}";
        if (!isset($this->protocols[$host_key])) {
            if (!isset($this->sockets[$host_key])) {
                $this->sockets[$host_key] = new Socket($host, $port, $this->connectTimeoutMS);
                $this->sockets[$host_key]->connect();
            }
            $this->protocols[$host_key] = new Protocol($this->sockets[$host_key]);
            if ($this->database != null) {
                $db = $this->selectDB($this->database);
                if ($this->username != null) {
                    $db->authenticate($this->username, $this->password, ['protocol' => $this->protocols[$host_key]]);
                }
            }
        }
        return $this->protocols[$host_key];
    }