The PHP Online Conference 2021


(PECL mongo >=0.9.0)

Mongo::__constructEl propósito de __construct


public Mongo::__construct ([ string $server [, array $options ]] )

Este método sobrescribe al constructor de MongoClient y desactiva la aceptación de escrituras.

Por favor, véase MongoClient::__construct() para la descripción de los parámetros.

Valores devueltos


La instanciación de esta clase emitirá una advertencia de tipo E_DEPRECATED, y desactivará la aceptación de escrituras.

Por favor, use MongoClient en su lugar.

add a note add a note

User Contributed Notes 4 notes

Arkadiy Kukarkin
10 years ago
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.
arie grapa
9 years ago
you can set mongo.auto_reconnect=1 in php.ini to cause it to automatically reconnect. This might be the default in future versions
rob at limeworks dot com dot au
9 years ago
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
guosheng1987 at 126 dot com
8 years ago
This is my coding sample
new Mongo();
new Mongo('mongodb://localhost:27017');
when I tried the two above,My page throw an exception with ' operation now in progress '
then I changed the localhost to ip address
new Mongo('mongodb://');
It works well!
To Top