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.
Пример #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;
 }
Пример #2
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;
     }
     /* MongoClient::$connected is deprecated in 1.5.0+, so count the list of
      * connected hosts instead.
      */
     return version_compare(phpversion('mongo'), '1.5.0', '<') ? $this->mongoClient->connected : count($this->mongoClient->getHosts()) > 0;
 }
Пример #3
0
<?php

$mongoClient = new MongoClient("mongodb://whisky:13000/?replicaset=seta");
$connections = $mongoClient->getConnections();
foreach ($connections as $con) {
    if ($con['connection']['connection_type_desc'] == "SECONDARY") {
        echo "Closing '{$con['hash']}':";
        $a->close($con['hash']);
    }
}
$mongoClient->selectDB("foo");
$mongoClient->getHosts();
$m->setReadPreference(MongoClient::RP_SECONDARY, array(array('dc' => 'east', 'use' => 'reporting'), array('dc' => 'west'), array()));
var_dump($m->getReadPreference());
$cursor = $collections->find();
$result = $cursor->next();
$info = $cursor->info();
MongoClient::killCursor($info['server'], $info['id']);
var_dump($mongoClient->listDBs());
$c1 = $m->selectCollection("foo", "bar.baz");
$c2 = $m->selectDB("foo")->selectCollection("bar.baz");
var_dump(MongoClient::_toString);