Reputation: 311
So I've recently inherited a LARGE body of php code, and it is less than optimal, here are the main problems:
My task is to configure a replication cluster and load balance reads across the slaves. I put the 'setSlaveOkay(true)' code in the wrapper class, which ideally should have been all that was needed...however direct access to 'mongo' and other classes in very many places in the code will not have the correct slaveOkay values set. Bad code appears in so many places, that it would be inhibitive to go in and fix every occurrence.
So ideally what I'm looking for is either:
I understand that people here have a strong inclination to give solutions that are done "the right way", however in this case, suggestions like "upgrade to the newest mongo and use read preferences" or "create a wrapper class ..." will not be useful. I inherited the code, I inherited the mongo installation. I need a quick and dirty fix that won't break the existing projects...going into the code and changing 500 invocations of the 'mongo' class to use the wrapper is not an option - it will introduce too many potential bugs in the code - and also there is no guarantee that other coders on the team will stop circumventing the wrapper class.
Thanks for your time.
Upvotes: 0
Views: 1527
Reputation: 36774
You can update to the latest PHP driver and use read preferences. This has nothing to do with the server side, unless you are using sharding, in which case you need a mongos
that comes with MongoDB 2.4+. But if you're not using sharding, you don't need a 2.4 cluster as read preferences are handled on the client side.
I would guess you have your connection string configured somewhere? If that's the case, you can just add ?readPreference=secondaryPrefered.
Upvotes: 1