downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

Mongo::getSlave> <Mongo::__get
[edit] Last updated: Fri, 24 Jun 2011

view this page in

Mongo::getHosts

(PECL mongo >=1.1.0)

Mongo::getHostsUpdates status for all hosts associated with this

Description

public array Mongo::getHosts ( void )

This method can only be used with a connection to a replica set. It returns the status of all of the hosts in the set and updates the connection information (the updating is invisible to the user).

This is called automatically by the driver every five seconds.

See the query section of this manual for information on distributing reads to slaves.

Parameters

This function has no parameters.

Return Values

Returns an array of information about the hosts in the set. Includes each host's hostname, id in the set, health (1 is healthy), the uptime, and how up-to-date the host is compared to the primary. For example, on a three-member replica set running locally, it might look something like:

Array
(
    [ubuntu:27017] => Array
        (
            [_id] => 0
            [name] => ubuntu:27017
            [health] => 1
            [state] => 1
            [stateStr] => PRIMARY
            [optime] => MongoTimestamp Object
                (
                    [sec] => 1
                    [inc] => 1291155754
                )

            [optimeDate] => MongoDate Object
                (
                    [sec] => 1291155754
                    [usec] => 0
                )

            [self] => 1
        )

    [ubuntu:27019] => Array
        (
            [_id] => 2
            [name] => ubuntu:27019
            [health] => 1
            [state] => 2
            [stateStr] => SECONDARY
            [uptime] => 91928
            [optime] => MongoTimestamp Object
                (
                    [sec] => 1
                    [inc] => 1291155754
                )

            [optimeDate] => MongoDate Object
                (
                    [sec] => 1291155754
                    [usec] => 0
                )

            [lastHeartbeat] => MongoDate Object
                (
                    [sec] => 1291158846
                    [usec] => 0
                )

        )

    [ubuntu:27018] => Array
        (
            [_id] => 1
            [name] => ubuntu:27018
            [health] => 1
            [state] => 2
            [stateStr] => SECONDARY
            [uptime] => 91944
            [optime] => MongoTimestamp Object
                (
                    [sec] => 1
                    [inc] => 1291155754
                )

            [optimeDate] => MongoDate Object
                (
                    [sec] => 1291155754
                    [usec] => 0
                )

            [lastHeartbeat] => MongoDate Object
                (
                    [sec] => 1291158846
                    [usec] => 0
                )

        )

)

This returns NULL if the connection is not connected to a replica set or has not been initialized, yet.



add a note add a note User Contributed Notes Mongo::getHosts - [0 notes]
There are no user contributed notes for this page.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites