(mongodb >=1.0.0)
MongoDB\Driver\Manager::getServers — 返回此管理器连接到的服务器
返回一个 array,其中包含此管理器连接到的 MongoDB\Driver\Server 实例。
注意: 由于驱动程序是延迟连接到数据库的,因此如果在对 MongoDB\Driver\Manager 执行操作之前调用此方法,则它可能返回一个空的 array。
此函数没有参数。
返回一个 array,其中包含此管理器连接到的 MongoDB\Driver\Server 实例。
示例 #1 MongoDB\Driver\Manager::getServers() 示例
<?php
$manager = new MongoDB\Driver\Manager("mongodb://:27017");
/* 驱动程序延迟连接到数据库服务器,因此 Manager::getServers()
* 最初可能会返回一个空数组。 */
var_dump($manager->getServers());
$command = new MongoDB\Driver\Command(['ping' => 1]);
$manager->executeCommand('db', $command);
var_dump($manager->getServers());
?>以上示例的输出类似于
array(0) {
}
array(1) {
[0]=>
object(MongoDB\Driver\Server)#3 (10) {
["host"]=>
string(9) "localhost"
["port"]=>
int(27017)
["type"]=>
int(1)
["is_primary"]=>
bool(false)
["is_secondary"]=>
bool(false)
["is_arbiter"]=>
bool(false)
["is_hidden"]=>
bool(false)
["is_passive"]=>
bool(false)
["last_hello_response"]=>
array(8) {
["isWritablePrimary"]=>
bool(true)
["maxBsonObjectSize"]=>
int(16777216)
["maxMessageSizeBytes"]=>
int(48000000)
["maxWriteBatchSize"]=>
int(1000)
["localTime"]=>
object(MongoDB\BSON\UTCDateTime)#4 (1) {
["milliseconds"]=>
int(1447267964517)
}
["maxWireVersion"]=>
int(3)
["minWireVersion"]=>
int(0)
["ok"]=>
float(1)
}
["round_trip_time"]=>
int(554)
}
}