From 895044720bab9d18442d116bfb796ea5a7f7ec64 Mon Sep 17 00:00:00 2001 From: Kristina Chodorow Date: Thu, 7 Jul 2011 14:17:31 +0000 Subject: [PATCH] fixed description of getSlave git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@313052 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/mongo/mongo/getslave.xml | 10 +++++++++- reference/mongo/queries.xml | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/reference/mongo/mongo/getslave.xml b/reference/mongo/mongo/getslave.xml index d2150d9f42..ceccdd623e 100644 --- a/reference/mongo/mongo/getslave.xml +++ b/reference/mongo/mongo/getslave.xml @@ -20,6 +20,14 @@ object. + + 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. + + See the query section 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 ---> +--> diff --git a/reference/mongo/queries.xml b/reference/mongo/queries.xml index 018c3f4cce..ba32caed79 100644 --- a/reference/mongo/queries.xml +++ b/reference/mongo/queries.xml @@ -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 + + Note that we have to do a query before a slave is chosen: slaves are chosen + lazily by the driver. Mongo::getSlave will return + &null; until a slave is used. + + You can see what the driver thinks is the current status of the set members by running Mongo::getHosts.