php8.5
Home/ Manual/ driver / server/ MongoDB\Driver\Server::getLatency

MongoDB\Driver\Server::getLatency

PHP function Edit on GitHub ✎

(mongodb >=1.0.0)

Returns the latency of this server in milliseconds

Description

MongoDB\Driver\Server::getLatency(): integer|null

Returns the latency of this server in milliseconds. This is the client's measured round trip time of a hello command.

Parameters Parameters

Return Values

Returns the latency of this server in milliseconds, or null if no latency has been measured (e.g. client is connected to a load balancer).

Errors/Exceptions

Changelog

VersionDescription
PECL mongodb 1.11.0This method will return null if no latency has been measured. In earlier versions, an integer was always returned and an unset value might be reported as -1.

Examples

MongoDB\Driver\Server::getLatency() example

php
<?php

$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017/");
$server = $manager->selectServer();

var_dump($server->getLatency());

?>

The above example will output something similar to:

output
int(592)

See Also

Source: reference/mongodb/mongodb/driver/server/getlatency.xml · from the official PHP manual (php/doc-en)