fixed description of getSlave

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@313052 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Kristina Chodorow 2011-07-07 14:17:31 +00:00
parent 261b11b5d1
commit 895044720b
2 changed files with 17 additions and 1 deletions

View file

@ -20,6 +20,14 @@
object.
</para>
<para>
When you create a connection to the database, the driver will not immediately
decide on a slave to use. Thus, after you connect, this function will return
&null; even if there are slaves available. When you first do a query with
slaveOkay set, at that point the driver will choose a slave for this
connection. At that point, this function will return the chosen slave.
</para>
<para>
See <link linkend="mongo.queries">the query section</link> of this manual for
information on distributing reads to slaves.
@ -62,4 +70,4 @@ End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
-->

View file

@ -64,10 +64,12 @@ $cursor = $c->find();
// on the Australian client
$m1 = new Mongo("mongodb://P", array("replicaSet" => true));
$m1->foo->bar->find()->slaveOkay()->getNext();
echo "m1's slave is ".$m1->getSlave()."\n";
// on the European client
$m2 = new Mongo("mongodb://P", array("replicaSet" => true));
$m2->foo->bar->find()->slaveOkay()->getNext();
echo "m2's slave is ".$m2->getSlave()."\n";
?>
@ -81,6 +83,12 @@ m1's slave is: australianHost
m2's slave is: europeanHost
</screen>
<para>
Note that we have to do a query before a slave is chosen: slaves are chosen
lazily by the driver. <function>Mongo::getSlave</function> will return
&null; until a slave is used.
</para>
<para>
You can see what the driver thinks is the current status of the set members
by running <function>Mongo::getHosts</function>.