Mongo::__construct
(PECL mongo >=0.9.0)
Mongo::__construct — The __construct purpose
Description
public Mongo::__construct
([ string
$server
[, array $options
]] )This method overwrites the MongoClient constructor and turns off acknowledged writes.
Please see MongoClient::__construct() for description of the parameters.
Return Values
Warning
Instanciating this class will emit E_DEPRECATED
warning, and turn off acknowledged writes.
Please use the MongoClient instead.
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с базами данных
- Расширения для работы с базами данных отдельных производителей
- MongoDB
- Дополнительно
- Функция Mongo::connectUtil() - Connects with a database server
- Функция Mongo::__construct() - The __construct purpose
- Функция Mongo::getPoolSize() - Get pool size for connection pools
- Функция Mongo::getSlave() - Returns the address being used by this for slaveOkay reads
- Функция Mongo::getSlaveOkay() - Get slaveOkay setting for this connection
- Функция Mongo::poolDebug() - Returns information about all connection pools.
- Функция Mongo::setPoolSize() - Set the size for future connection pools.
- Функция Mongo::setSlaveOkay() - Change slaveOkay setting for this connection
- Функция Mongo::switchSlave() - Choose a new secondary for slaveOkay reads
Коментарии
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.
you can set mongo.auto_reconnect=1 in php.ini to cause it to automatically reconnect. This might be the default in future versions
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
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://127.0.0.1:27017');
It works well!