Skip to content

Commit 451f72c

Browse files
committed
PHPLIB-151: Use IPv4 localhost address for default URI
This should help avoid failed IPv6 connections when "localhost" resolves to an IPv6 literal and mongod does not have `net.ipv6}} enabled to listen for IPv6.
1 parent cbe03b2 commit 451f72c

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Client
2828
* @param array $options Additional connection string options
2929
* @param array $driverOptions Driver-specific options
3030
*/
31-
public function __construct($uri = 'mongodb://localhost:27017', array $options = [], array $driverOptions = [])
31+
public function __construct($uri = 'mongodb://127.0.0.1:27017', array $options = [], array $driverOptions = [])
3232
{
3333
$this->manager = new Manager($uri, $options, $driverOptions);
3434
$this->uri = (string) $uri;

tests/ClientTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function testConstructorDefaultUri()
1515
{
1616
$client = new Client();
1717

18-
$this->assertEquals('mongodb://localhost:27017', (string) $client);
18+
$this->assertEquals('mongodb://127.0.0.1:27017', (string) $client);
1919
}
2020

2121
public function testToString()

0 commit comments

Comments
 (0)