MongoDB\Driver\Manager::getServers

(mongodb >=1.0.0)

MongoDB\Driver\Manager::getServers — Retourner les serveurs auxquels ce gestionnaire est connectĂ©

Description

final public function MongoDB\Driver\Manager::getServers(): array

Retourne un tableau d'instances MongoDB\Driver\Server auxquelles ce gestionnaire est connecté.

Note: Étant donnĂ© que le pilote se connecte paresseusement Ă  la base de donnĂ©es, cette mĂ©thode peut retourner un tableau vide s'il est appelĂ© avant d'exĂ©cuter une opĂ©ration sur le MongoDB\Driver\Manager.

Liste de paramĂštres

Cette fonction ne contient aucun paramĂštre.

Valeurs de retour

Retourne un tableau d'instances MongoDB\Driver\Server auxquelles ce gestionnaire est connecté.

Erreurs / Exceptions

  • Lance une exception MongoDB\Driver\InvalidArgumentException lors d'une erreur survenue pendant l'analyse d'un argument.

Exemples

Exemple #1 Exemple avec MongoDB\Driver\Manager::getServers()

<?php

$manager
= new MongoDB\Driver\Manager("mongodb://localhost:27017");

/* The driver connects to the database server lazily, so Manager::getServers()
* may initially return an empty array. */
var_dump($manager->getServers());

$command = new MongoDB\Driver\Command(['ping' => 1]);
$manager->executeCommand('db', $command);

var_dump($manager->getServers());

?>

Résultat de l'exemple ci-dessus est similaire à :

array(0) {
}
array(1) {
  [0]=>
  object(MongoDB\Driver\Server)#3 (10) {
    ["host"]=>
    string(9) "localhost"
    ["port"]=>
    int(27017)
    ["type"]=>
    int(1)
    ["is_primary"]=>
    bool(false)
    ["is_secondary"]=>
    bool(false)
    ["is_arbiter"]=>
    bool(false)
    ["is_hidden"]=>
    bool(false)
    ["is_passive"]=>
    bool(false)
    ["last_hello_response"]=>
    array(8) {
      ["isWritablePrimary"]=>
      bool(true)
      ["maxBsonObjectSize"]=>
      int(16777216)
      ["maxMessageSizeBytes"]=>
      int(48000000)
      ["maxWriteBatchSize"]=>
      int(1000)
      ["localTime"]=>
      object(MongoDB\BSON\UTCDateTime)#4 (1) {
        ["milliseconds"]=>
        int(1447267964517)
      }
      ["maxWireVersion"]=>
      int(3)
      ["minWireVersion"]=>
      int(0)
      ["ok"]=>
      float(1)
    }
    ["round_trip_time"]=>
    int(554)
  }
}

Voir aussi

add a note

User Contributed Notes

There are no user contributed notes for this page.