Skip to content

Instantly share code, notes, and snippets.

@leozc
Last active December 20, 2015 11:49
Show Gist options
  • Save leozc/6126556 to your computer and use it in GitHub Desktop.
Save leozc/6126556 to your computer and use it in GitHub Desktop.
Host this php on php-fpm + nginx, each page hit creates TWO Pairs of connections to replicaset, FOUR Authentication done (primary + secondary) * 2
<?
// simple mongoclient dumpper
$a=getMongo();
$b=getMongo();
var_dump($a->getConnectionss());
print("===================================SECOND MONGO CONN REQUEST ===================================\n");
var_dump($b->getConnectionss());
function getMongo(){//{{{
$mongo = new MongoClient(MG_HOST, array(
'replicaSet' => MG_REPLICASET,
'password'=>MG_PWD,
'username'=>MG_USER,
'db'=>MG_DB,
'journal' => true,
"readPreference"=> MongoClient::RP_SECONDARY_PREFERRED
)
);
$mgdb = $mongo->{MG_DB};
return $mongo;
}
?>
@jmikola
Copy link

jmikola commented Aug 1, 2013

@leozc: Please format the var_dump output with monospace formatting (three ` characters on a line before and after will do it). It's a bit hard to read in the current state.

@leozc
Copy link
Author

leozc commented Aug 14, 2013

Re:jmlkola.

@leozc: The error you're seeing is because the connection string hostname doesn't match what the servers themselves identify as. Take a look at mongo_connection_ismaster and look for the retval = 3 case.

Very nice hint! It ends up it is a domain name alias problem, let me investigate further...

@leozc
Copy link
Author

leozc commented Aug 15, 2013

Take a look at mongo_connection_ismaster and look for the retval = 3 case. helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment