MongoClient::getConnections

(PECL mongo >=1.3.0)

MongoClient::getConnections返回所有已打开连接的信息

This extension that defines this method is deprecated. Instead, the MongoDB extension should be used. There is no equivalent for this method in the new extension.

说明

public static MongoClient::getConnections ( void ) : array

返回所有已打开连接的数组,并且每个服务器的信息

参数

此函数没有参数。

返回值

打开连接的一个 array

范例

Example #1 MongoClient::getConnections() 例子

<?php
$m 
= new MongoClient;
var_dump($m->getConnections());
?>

以上例程的输出类似于:

array(1) {
  [0]=>
  array(3) {
    ["hash"]=>
    string(26) "localhost:27017;-;X;56052"
    ["server"]=>
    array(3) {
      ["host"]=>
      string(10) "localhost"
      ["port"]=>
      int(27017)
      ["pid"]=>
      int(56052)
    }
    ["connection"]=>
    array(8) {
      ["last_ping"]=>
      int(1354076401)
      ["last_ismaster"]=>
      int(0)
      ["ping_ms"]=>
      int(0)
      ["connection_type"]=>
      int(1)
      ["connection_type_desc"]=>
      string(10) "STANDALONE"
      ["max_bson_size"]=>
      int(16777216)
      ["tag_count"]=>
      int(0)
      ["tags"]=>
      array(0) {
      }
    }
  }
}
add a note add a note

User Contributed Notes 1 note

up
-1
pankaj dot shuklamca at gmail dot com
7 years ago
getConnections() function return all the connected hosts irrespective to replica set. Means if your application is making connection from 2 replicaset parallely - it will return hosts of both the replica set
To Top