nicktacular / php-mongo-session

A PHP session handler with a Mongo DB backend.
MIT License
18 stars 6 forks source link

replica set secondary support - slaveok #3

Closed rocksfrow closed 10 years ago

rocksfrow commented 10 years ago

When defining $config['repicaSet'] and using multiple hosts in the URI, I am getting the following exception from the secondary:

[Sun Jul 27 18:06:35 2014] [warn] [client 71.179.201.210] mod_fcgid: stderr: PHP Fatal error:  Uncaught exception 'MongoCursorException' with message '10.103.30.33:27017: not master and slaveOk=false' in /home/kyler/repos/php-mongo-session/MongoSession.php:283

.slaveOk() needs to be called to allow a read query from a secondary or this exception is thrown. I get the same error from the mongo CLI on my secondary.

slaveOk() is now deprecated and 'Read Preferences' are now supposed to be used. So it would need to fallback to slaveOk() if Read Prefs are not available. http://php.net/manual/en/mongo.readpreferences.php

rocksfrow commented 10 years ago

@nicktacular are you using this class with a replica set? What version php mongo driver, and what version mongodb?

I am having file locking issues with a replica set where it'll fail to properly unlock (a writeconcern exception occurs after ->remove).

rocksfrow commented 10 years ago

So I was having a bunch of weird issues and getting exceptions all related to actions that shouldn't be taken on my slave. It turned out that setting 'replicaSet' in $options isn't sufficient. You must supply the replicaSet in the URI. (at least that is my experience). After putting /?replicaSet=xxx on the end of the URI I am running great.

rocksfrow commented 10 years ago

Ahh, I see. I assumed the class options were getting passed down to the Mongo() usage but I was wrong. I went ahead and added another config option 'connection_opts' which is an array of options to pass down to Mongo/MongoClient... like replicaSet, connecttimeoutMS, etc... feel free to pull/merge these changes.

nicktacular commented 10 years ago

Yes, I'm using this with a replica set and prefer passing the options via the actual string as you say with mongo://host1,host2,host3/?replicaSet=app. Feel free to issue a pull request with the additional connection_opts to pass to MongoClient.