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

MongoDB\Driver\Server::getPort

PHP function Edit on GitHub ✎

(mongodb >=1.0.0)

Returns the port on which this server is listening

Description

MongoDB\Driver\Server::getPort(): int

Returns the port on which this server is listening.

Parameters Parameters

Return Values

Returns the port on which this server is listening.

Errors/Exceptions

Examples

MongoDB\Driver\Server::getPort() example

php
<?php

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

var_dump($server->getPort());

?>

The above example will output:

output
int(27017)

See Also

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