downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Mongo::dropDB> <Mongo::connectUtil
[edit] Last updated: Fri, 18 Sep 2009

view this page in

Mongo::__construct

(PECL mongo >=0.9.0)

Mongo::__constructCreates a new database connection object

Описание

Mongo::__construct ([ string $server = NULL [, boolean $connect = TRUE [, boolean $persistent = FALSE [, boolean $paired = FALSE ]]]] )

Параметри

server

The server name.

connect

If the driver should connect to the database before returning.

persistent

If the connection should be persistent.

paired

If the connection should be paired.

Връщани стойности

Returns a new database connection object.

Грешки/Изключения

Throws MongoConnectionException if it tries and fails to connect to the database.



Mongo::dropDB> <Mongo::connectUtil
[edit] Last updated: Fri, 18 Sep 2009
 
add a note add a note User Contributed Notes Mongo::__construct
sonic1000 at gmx dot de 08-Mar-2012 03:46
Please note, that somehow MongoDB will throw an Exception if you try to connect to a string like mongodb://A,B,C and one of the repsets is in revover mode:

_id" : 0,
"name" : "A:27017",
"health" : 1,
"state" : 3,
"stateStr" : "RECOVERING"
Niek at sourcebox dot nl 16-Feb-2012 03:01
After a big crash on our mongo database replica-set we started to investigate why PHP hangs itself when a server seems to disappear. It seems that this library isn't doing a very good job with connecting to a replicate set.

In the official mongo manual it says:
"The driver then connects to all servers on the seed list, perhaps in parallel to minimize connect time .." PHP doesn't do parallel. It tries every seed from the list one at the time. After one fails it goes to the next etc. This is how PHP works and i doubt it can be altered. So the problem starts when you connect like:
new Mongo("mongodb://192.168.0.100,192.168.0.101", array("replicaSet" => "myReplicaSet"));

When the server 192.168.0.100 crashes, all new connections will take at least 20 seconds (20 seconds connection timeout) before it moves to the second server. The webserver will come crashing down with all these hanging PHP instances. (If the server is still up though only the mongo service is down everything does continue to work without the delay though.)

The timeout setting will remedy a bit of this behavior making the connection like: (100 ms timeout)
new Mongo("mongodb://192.168.0.100,192.168.0.101", array("replicaSet" => "myReplicaSet", "timeout" => 100));
All new connections have a additional delay of 100 ms when there is a server crash which is better then the 20000 ms default value. Still not perfect but workable.

This behavior isn't really excepted when reading the manuals and people may think they have an failover mongo. This isn't the case when you are not using the timeout property.
Sid 19-Sep-2011 07:06
Well it looks like specifying the username, and password as an option in the option array DOES NOT work with replica sets properly.  I got a bunch of unauthorized exceptions when trying to do inserts.  Best bet is to specify username and password via the connection string.
rob at limeworks dot com dot au 02-Sep-2011 02:14
Note that even if you authenticate with a database specific user during instantiation of the Mongo class, it's still necessary to select the database before you try and use it.

Might sound common sense, but hopefully it will help someone anyway :D
Julius 04-Aug-2011 03:33
It's worth noting that authentication is not available in replicaSet with sharding before MongoDB version 1.9.1

http://www.mongodb.org/display/DOCS/Security+and+Authentication
arie grapa 12-Apr-2011 04:49
you can set mongo.auto_reconnect=1 in php.ini to cause it to automatically reconnect. This might be the default in future versions
Arkadiy Kukarkin 06-May-2010 02:17
The behavior of persistent connections is somewhat mysterious, but it appears that they remain for the duration of the process with some internal timeout value, and not until the end of script execution as you might expect based on the wording here and in close().

That is, the connection will remain open even once every object that used it is out of scope and can be accessed again with the persist key. This is consistent with the way e.g. DBI does things, but still somewhat confusing when not made explicit. A related issue is that under certain conditions php seems to open multiple connections even using the same key, but that's more of a bug report.
cap at unagon dot com 26-Feb-2010 02:38
Be sure *not* to append a slash at the end of the mongo URL.

$m = new Mongo("mongodb://dbuser:dbpasswd@localhost/");

in my case led to an empty web page and complete crash of the PHP interpreter, no chance to catch this as an exception.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites