Do PHP mongodb driver check for replica set's master on every request

From: http://stackoverflow.com/questions/12163498/do-php-mongodb-driver-check-for-replica-sets-master-on-every-request



A typical PHP call to mongodb's replica set


$m1 = new Mongo("mongodb://sf2.example.com,ny1.example.com", 

      array("replicaSet" => "myReplSet"));

The document said:


// you only need to pass a single seed, the driver will derive the full list and

// find the master from this seed

Questions:


So does it mean the driver will derive the full list on every request? Or they will cache it?


If they cache it, will it cause a problem during fail over? Write to the slave while it is being demoted as secondary


Will the driver refresh the server list and retry the write when it experienced write error?




To answer your questions:

1) The PHP driver, like most MongoDB drivers, will cache the connection information once it derives it.

2) In the event of a fail-over, the former primary node will drop all connections to all clients. The next time the driver attempts to read or write on the socket, it will get an error. If the driver can't reconnect to the new primary node at the time of the operation, it will throw a PHP MongoConnectionException exception.

3) It is up to your application to catch this exception and to retry when this exception has been thrown.

Reference: http://php.net/manual/en/mongo.connecting.php


你可能感兴趣的:(request,document,master,single)