<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Updates status for all associated hosts</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mongoclient.getconnections.html">MongoClient::getConnections</a></div> <div class="next" style="text-align: right; float: right;"><a href="mongoclient.getreadpreference.html">MongoClient::getReadPreference</a></div> <div class="up"><a href="class.mongoclient.html">MongoClient</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="mongoclient.gethosts" class="refentry"> <div class="refnamediv"> <h1 class="refname">MongoClient::getHosts</h1> <p class="verinfo">(PECL mongoclient >=1.1.0)</p><p class="refpurpose"><span class="refname">MongoClient::getHosts</span> — <span class="dc-title">Updates status for all associated hosts</span></p> </div> <div class="refsect1 description" id="refsect1-mongoclient.gethosts-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">array</span> <span class="methodname"><strong>MongoClient::getHosts</strong></span> ( <span class="methodparam">void</span> )</div> <p class="para rdfs-comment"> This method is only useful with a connection to a replica set. It returns the status of all of the hosts in the set. Without a replica set, it will just return an array with one element containing the host that you are connected to. </p> <p class="para"> See <a href="mongo.queries.html" class="link">the query section</a> of this manual for information on distributing reads to secondaries. </p> </div> <div class="refsect1 parameters" id="refsect1-mongoclient.gethosts-parameters"> <h3 class="title">Parameters</h3> <p class="para">This function has no parameters.</p> </div> <div class="refsect1 returnvalues" id="refsect1-mongoclient.gethosts-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> 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. For example, on a three-member replica set, it might look something like: </p> <div class="example-contents screen"> <div class="returnvaluescode"><pre class="returnvaluescode">array(3) { ["A:27017"]=> array(4) { ["host"]=> "A" ["port"]=> 27017 ["health"]=> int(1) ["state"]=> int(2) ["ping"]=> int(369) ["lastPing"]=> int(1309470644) } ["B:27017"]=> array(4) { ["host"]=> "B" ["port"]=> 27017 ["health"]=> int(1) ["state"]=> int(1) ["ping"]=> int(139) ["lastPing"]=> int(1309470644) } ["C:27017"]=> array(4) { ["host"]=> "C" ["port"]=> 27017 ["health"]=> int(1) ["state"]=> int(2) ["ping"]=> int(1012) ["lastPing"]=> int(1309470644) } }</pre> </div> </div> </div> <div class="refsect1 changelog" id="refsect1-mongoclient.gethosts-changelog"> <h3 class="title">Changelog</h3> <p class="para"> <table class="doctable informaltable"> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>1.2.10</td> <td> <p class="para"> Support for non-replicasets was added. </p> <p class="para"> The returned array elements now also include the <em>hostname</em> and <em>port</em>. </p> </td> </tr> </tbody> </table> </p> </div> <div class="refsect1 seealso" id="refsect1-mongoclient.gethosts-seealso"> <h3 class="title">See Also</h3> <ul class="simplelist"> <li class="member"> <span class="function"><a href="mongoclient.getconnections.html" class="function" rel="rdfs-seeAlso">MongoClient::getConnections()</a> - Return info about all open connections</span></li> </ul> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mongoclient.getconnections.html">MongoClient::getConnections</a></div> <div class="next" style="text-align: right; float: right;"><a href="mongoclient.getreadpreference.html">MongoClient::getReadPreference</a></div> <div class="up"><a href="class.mongoclient.html">MongoClient</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>