Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bbff3cb

Browse files
authored
Disable mongoc_client reuse between connections (#3197)
1 parent c23cadd commit bbff3cb

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

‎src/Connection.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ protected function createConnection(string $dsn, array $config, array $options):
217217
$options['password'] = $config['password'];
218218
}
219219

220+
if (isset($config['name'])) {
221+
$driverOptions += ['connectionName' => $config['name']];
222+
}
223+
220224
return new Client($dsn, $options, $driverOptions);
221225
}
222226

‎tests/ConnectionTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,34 @@ public function testQueryLog()
277277
}
278278
}
279279

280+
public function testQueryLogWithMultipleClients()
281+
{
282+
$connection = DB::connection('mongodb');
283+
$this->assertInstanceOf(Connection::class, $connection);
284+
285+
// Create a second connection with the same config as the first
286+
// Make sure to change the name as it's used as a connection identifier
287+
$config = $connection->getConfig();
288+
$config['name'] = 'mongodb2';
289+
$secondConnection = new Connection($config);
290+
291+
$connection->enableQueryLog();
292+
$secondConnection->enableQueryLog();
293+
294+
$this->assertCount(0, $connection->getQueryLog());
295+
$this->assertCount(0, $secondConnection->getQueryLog());
296+
297+
$connection->table('items')->get();
298+
299+
$this->assertCount(1, $connection->getQueryLog());
300+
$this->assertCount(0, $secondConnection->getQueryLog());
301+
302+
$secondConnection->table('items')->get();
303+
304+
$this->assertCount(1, $connection->getQueryLog());
305+
$this->assertCount(1, $secondConnection->getQueryLog());
306+
}
307+
280308
public function testDisableQueryLog()
281309
{
282310
// Disabled by default

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /