PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

Debugging Connections with the MongoDB PHP driver

Note: This article was originally published at Planet PHP on 11 December 2012.
Planet PHP

Debugging Connections with the MongoDB PHP driver

Tokyo, Japan Tuesday, December 11th 2012, 10:13 JST

In a previous article I already mentioned that the 1.3 version of the MongoDB driver has improved logging functionality to aid with debugging connection issues. I've already briefly introduced MongoClient::getConnections(), but it provides a bit more information than I have already shown. The other improvement are changes to the MongoLog class.

Mongo::getConnections()

Mongo::getConnections() returns information about all the connections that the connection manager knows about. Besides basic information such as the connection's hash ($m-getConnections()[0]['hash']) it also returns the following information:

  • hash: the connection's identifier; f.e.: string(22) "whisky:27017;-;X;21093".

  • server: contains an element for each of the elements in the hash, but broken up.

  • connection: contains information about the connection and server it is connected to. It is an array with the following fields:

    • last_ping: timestamp that indicates when the server was last pinged; for example: int(1352479219).

    • last_ismaster: timestamp that indicates when the topology of a replicaset was last checked for; in the case of a standalone connection, this is: int(0).

    • ping_ms: the time it takes to get to the server and back again in milliseconds, this is very often just 0.

    • connection_type: the type of connection. The value is: 1 for a standalone connection, 2 for multiple "mongos" connections and 3 for a replica set connection.

    • connection_type_desc: a string representation of the above types.

    • max_bson_size: the maximum size of a document, right now, that is int(16777216) (bytes).

    • tag_count: the number of tags associated with this mongod server. I will explain what tags are and how you can use them in a future article on Read Preferences.

    • tags: an array containing all the tags.

As an example, this is what is returned for my replica set test setup:

getConnections()); ?

Which returns:

Array ([0] = Array ([hash] = whisky:13000;seta;X;3955 [server] = Array a 'exploded' hash ([host] = whisky [port] = 13000 [repl_set_name] = seta [pid] = 3955) [connection] = Array ([last_ping] = 1353515082 [last_ismaster] = 1353515082 [ping_ms] = 0 a ping time [connection_type] = 4 [connection_type_desc] = SECONDARY a secondary node [max_bson_size] = 16777216 a 16MB document limit [tag_count] = 2 [tags] = Array a tags ([0] = dc:west [1] = use:accounting))) [1] = Array ([hash] = whisky:13001;seta;X;3955 [server] = Array ([host] = whisky [port] = 13001 [repl_set_name] = seta [pid] = 3955) [connection] = Array ([last_ping] = 1353515082 [last_ismaster] = 1353515082 [ping_ms] = 0 [connection_type] = 2 [connection_type_desc] = PRIMARY [max_bson_size] = 16777216 [tag_count] = 2 [tags] = Array ([0] = dc:ea

Truncated by Planet PHP, read more at the original (another 8369 bytes)