MongoClient::getHosts PHP Метод

getHosts() публичный Метод

Updates status for all associated hosts
public getHosts ( ) : array
Результат array - Returns an array of information about the hosts in the set. Includes each host's hostname, its health (1 is healthy), its state (1 is primary, 2 is secondary, 0 is anything else), the amount of time it took to ping the server, and when the last ping occurred.
    public function getHosts()
    {
        $this->connect();
        // Ensure pings are up-to-date
        foreach ($this->hosts as $host) {
            $this->pingHost($host['host'], $host['port']);
        }
        return $this->hosts;
    }

Usage Example

Пример #1
0
 /**
  * Checks whether the connection is initialized and connected.
  *
  * @return boolean
  */
 public function isConnected()
 {
     if (!($this->mongoClient instanceof \MongoClient || $this->mongoClient instanceof \Mongo)) {
         return false;
     }
     return count($this->mongoClient->getHosts()) > 0;
 }
All Usage Examples Of MongoClient::getHosts