<!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>Choose a new secondary for slaveOkay reads</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mongo.setslaveokay.html">Mongo::setSlaveOkay</a></div> <div class="next" style="text-align: right; float: right;"><a href="ref.mongo.html">Mongo Functions</a></div> <div class="up"><a href="class.mongo.html">Mongo</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="mongo.switchslave" class="refentry"> <div class="refnamediv"> <h1 class="refname">Mongo::switchSlave</h1> <p class="verinfo">(PECL mongo >=1.1.0)</p><p class="refpurpose"><span class="refname">Mongo::switchSlave</span> — <span class="dc-title">Choose a new secondary for slaveOkay reads</span></p> </div> <div class="refsect1 description" id="refsect1-mongo.switchslave-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">string</span> <span class="methodname"><strong>Mongo::switchSlave</strong></span> ( <span class="methodparam">void</span> )</div> <p class="para rdfs-comment"> This choses a random secondary for a connection to read from. It is called automatically by the driver and should not need to be used. It calls <span class="function"><a href="mongoclient.gethosts.html" class="function">MongoClient::getHosts()</a></span> (to refresh the status of hosts) and <span class="function"><a href="mongo.getslave.html" class="function">Mongo::getSlave()</a></span> (to get the return value). </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-mongo.switchslave-parameters"> <h3 class="title">Parameters</h3> <p class="para">This function has no parameters.</p> </div> <div class="refsect1 returnvalues" id="refsect1-mongo.switchslave-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> The address of the secondary this connection is using for reads. This may be the same as the previous address as addresses are randomly chosen. It may return only one address if only one secondary (or only the primary) is available. </p> <p class="para"> For example, if we had a three member replica set with a primary, secondary, and arbiter this method would always return the address of the secondary. If the secondary became unavailable, this method would always return the address of the primary. If the primary also became unavailable, this method would throw an exception, as an arbiter cannot handle reads. </p> </div> <div class="refsect1 errors" id="refsect1-mongo.switchslave-errors"> <h3 class="title">Errors/Exceptions</h3> <p class="para"> Throws a <a href="class.mongoexception.html" class="classname">MongoException</a> (error code 15) if it is called on a non-replica-set connection. It will also throw <a href="class.mongoexception.html" class="classname">MongoException</a>s if it cannot find anyone (primary or secondary) to read from (error code 16). </p> </div> <div class="refsect1 changelog" id="refsect1-mongo.switchslave-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.11</td> <td>Emits <strong><code>E_DEPRECATED</code></strong> when used.</td> </tr> </tbody> </table> </p> </div> <div class="refsect1 seealso" id="refsect1-mongo.switchslave-seealso"> <h3 class="title">See Also</h3> <ul class="simplelist"> <li class="member"><a href="mongo.readpreferences.html" class="xref">Read Preferences</a></li> </ul> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mongo.setslaveokay.html">Mongo::setSlaveOkay</a></div> <div class="next" style="text-align: right; float: right;"><a href="ref.mongo.html">Mongo Functions</a></div> <div class="up"><a href="class.mongo.html">Mongo</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>