From d0146aabde81aaa681bdbf5c37ed5563f31df448 Mon Sep 17 00:00:00 2001 From: Kristina Chodorow Date: Wed, 26 Jan 2011 22:22:50 +0000 Subject: [PATCH] improved connection info git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@307768 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/mongo/mongo.xml | 10 ++-- reference/mongo/mongo/close.xml | 60 ++++------------------- reference/mongo/mongocursor/info.xml | 2 +- reference/mongo/mongocursor/slaveokay.xml | 38 +++++++++++++- reference/mongo/queries.xml | 6 ++- 5 files changed, 57 insertions(+), 59 deletions(-) diff --git a/reference/mongo/mongo.xml b/reference/mongo/mongo.xml index 317b7c4b79..fbe1aafb55 100644 --- a/reference/mongo/mongo.xml +++ b/reference/mongo/mongo.xml @@ -11,11 +11,10 @@
&reftitle.intro; - The connection point between MongoDB and PHP. + A connection between PHP and MongoDB. - This class is used to initiate a connection and for database server commands. - A typical use is: + This class is used to create and manage connections. A typical use is: foo; // get the database named "foo" - See Mongo::__construct for more information about - creating connections. + See Mongo::__construct and the section on + connecting for more information + about creating connections.
diff --git a/reference/mongo/mongo/close.xml b/reference/mongo/mongo/close.xml index b2c5485def..111769ee40 100644 --- a/reference/mongo/mongo/close.xml +++ b/reference/mongo/mongo/close.xml @@ -4,7 +4,7 @@ Mongo::close - Closes this database connection + Closes this connection @@ -16,61 +16,19 @@ This method does not need to be called, except in unusual circumstances. The driver will cleanly close the database - connection when the Mongo object goes out of scope. + connection when this Mongo instance goes out of scope. - If you are using a service where objects do not go out of scope - between requests, you may wish to call close() at the end of - your program to keep old connections from hanging around. - However, it is probably more efficient to take advantage of - this fact and simply use a persistent connection, which will - automatically create a connection if needed and use it for as - many requests as the application server allows it to exist. + If objects do not go out of scope between requests, you may wish to call + this method at the end of your program to keep old connections from hanging + around. However, it is probably more efficient use a persistent connection, + which will automatically create a connection if needed and use it for as + many requests as possible. - You may also wish to call close() if you are unsure of the - state of a connection and wish to guarantee a new connection will - happen. For example: + If you are connected to a replica set, close() will only close the connection + to the primary. - - - -connect(); - -?> -]]> - - - - - vs. - - - - -close(); -$mongo->connect(); - -?> -]]> - - diff --git a/reference/mongo/mongocursor/info.xml b/reference/mongo/mongocursor/info.xml index 84cd5bfcf6..ec0805a543 100644 --- a/reference/mongo/mongocursor/info.xml +++ b/reference/mongo/mongocursor/info.xml @@ -58,7 +58,7 @@ returned by the server in the current batch), and server (which server the query was sent to—useful in conjunction with - MongoCursor::slaveOkay. + MongoCursor::slaveOkay). diff --git a/reference/mongo/mongocursor/slaveokay.xml b/reference/mongo/mongocursor/slaveokay.xml index d517dd1517..5987d4f474 100644 --- a/reference/mongo/mongocursor/slaveokay.xml +++ b/reference/mongo/mongocursor/slaveokay.xml @@ -14,7 +14,43 @@ booleanokaytrue - This method will override the static class variable slaveOkay. + Calling this will make the driver route reads to slaves if: + + + + You are using a replica set and + + + + + You created a Mongo instance using the option + "replicaSet" => true and + + + + + There is a healthy slave that can be reached by the driver. + + + + You can check which server was used for this query by calling + MongoCursor::info after running the query. It's + server field will show which server the query was sent to. + + + Note that you should use this function even if you do not use the automatic + routing to slaves. If you connect directly to a secondary in a replica set, + you still need to call this function, which basically tells the database that + you are aware that you might be getting older data and you're okay with that. + If you do not call this, you'll get "not master" errors when you try to + query. + + + This method will override the static class variable + MongoCursor::slaveOkay. It will also override + Mongo::setSlaveOkay, + MongoDB::setSlaveOkay and + MongoCollection::setSlaveOkay. diff --git a/reference/mongo/queries.xml b/reference/mongo/queries.xml index 055c40967e..f28109dfa3 100644 --- a/reference/mongo/queries.xml +++ b/reference/mongo/queries.xml @@ -81,7 +81,11 @@ m2's slave is: ip1 If we continued to create new Mongos, we should get a - fairly even distribution between ip1 and ip2. + fairly even distribution between ip1 and ip2. Keep in mind that all + secondaries listed by the isMaster command will be in + the pool of possible readers (even ones with priority 0 or slaveDelay set). + If you have certain servers you do not wish to read from, either route reads + manually or add the hidden option to the server's replica set configuration.