Skip to content

Commit 1d3ee76

Browse files
authored
Merge pull request #1 from reactphp-x/2.0.0
2.0.0
2 parents b501fc2 + b21e5b9 commit 1d3ee76

File tree

7 files changed

+20
-15
lines changed

7 files changed

+20
-15
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ $db->addConnection([
4141
'max_connections' => 10, // max 10 connection
4242
'max_wait_queue' => 110, // how many sql in queue
4343
'wait_timeout' => 5,// wait time include response time
44-
'keep_alive' => 10, //
44+
'idle' => 60, //
4545
]
4646
]);
4747

composer.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
],
1212
"require": {
1313
"php": "^8.1",
14-
"reactphp-x/mysql-pool": "^1.0",
1514
"react/async": "^4 || ^3 || ^2",
16-
"illuminate/database": "^11.19"
15+
"illuminate/database": "^11.19",
16+
"reactphp-x/mysql-pool": "^2.0@dev"
1717
},
1818
"autoload": {
1919
"psr-4": {
2020
"ReactphpX\\Orm\\": "src"
2121
}
22-
}
22+
},
23+
"minimum-stability": "dev",
24+
"prefer-stable": true
2325
}

examples/01.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
});
3232

3333
print_r(DB::getQueryLog());
34-
DB::disconnect();
34+
// DB::disconnect();
3535

3636

3737

examples/04.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
// true
2323
var_dump(DB::table('test_users')->where('name', 'test-failed')->count() === 0);
2424

25-
echo 'pool_count:'. DB::getPdo()->getPoolCount() . PHP_EOL;
26-
echo 'idleConnectionCount:'. DB::getPdo()->idleConnectionCount() . PHP_EOL;
25+
// echo 'pool_count:'. DB::getPdo()->getPoolCount() . PHP_EOL;
26+
// echo 'idleConnectionCount:'. DB::getPdo()->idleConnectionCount() . PHP_EOL;
2727

2828
// success
2929
DB::table('test_users')->where('name', 'test-success')->delete();
@@ -40,8 +40,8 @@
4040
// true
4141
var_dump(DB::table('test_users')->where('name', 'test-success')->count() === 1);
4242

43-
echo 'pool_count:'. DB::getPdo()->getPoolCount() . PHP_EOL;
44-
echo 'idleConnectionCount:'. DB::getPdo()->idleConnectionCount() . PHP_EOL;
43+
// echo 'pool_count:'. DB::getPdo()->getPoolCount() . PHP_EOL;
44+
// echo 'idleConnectionCount:'. DB::getPdo()->idleConnectionCount() . PHP_EOL;
4545

4646

4747
DB::disconnect();

examples/base.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
'max_connections' => 10, // max 10 connection
3131
'max_wait_queue' => 110, // how many sql in queue
3232
'wait_timeout' => 5,// wait time include response time
33-
'keep_alive' => 10, //
33+
'idle' => 60, //
3434
]
3535
]);
3636

@@ -186,8 +186,8 @@ public function posts()
186186

187187
\React\EventLoop\Loop::addPeriodicTimer(1, function () {
188188
if (DB::getPdo()) {
189-
echo 'pool_count:'. DB::getPdo()->getPoolCount() . PHP_EOL;
190-
echo 'idleConnectionCount:'. DB::getPdo()->idleConnectionCount() . PHP_EOL;
189+
// echo 'pool_count:'. DB::getPdo()->getPoolCount() . PHP_EOL;
190+
// echo 'idleConnectionCount:'. DB::getPdo()->idleConnectionCount() . PHP_EOL;
191191
} else {
192192
var_dump('pool closed');
193193
\React\EventLoop\Loop::stop();

src/AsyncMysqlConnection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ public function beginTransaction()
339339
throw new Exception("had in transaction");
340340
}
341341

342-
$connection = \React\Async\await($this->getPdo()->getIdleConnection());
342+
$connection = \React\Async\await($this->getPdo()->getConnection());
343343
\React\Async\await($connection->query('BEGIN'));
344344
$db = clone $this;
345345
$db->setPdo($connection);

src/AsyncMysqlConnector.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ public function connect($config)
2828
$database = $config['database'];
2929

3030
return static::$pool = new Pool(
31-
$username . ':' . $password . '@' . $host . '/' . $database . '?charset=' . $charset,
32-
$config['pool'] ?? []
31+
$username . ':' . $password . '@' . $host . '/' . $database . '?charset=' . $charset.'&idle='.($config['idle'] ?? 30),
32+
$config['pool']['min_connections'] ?? 1,
33+
$config['pool']['max_connections'] ?? 10,
34+
$config['pool']['max_wait_queue'] ?? 500,
35+
$config['pool']['wait_timeout'] ?? 0,
3336
);
3437
}
3538
}

0 commit comments

Comments
 (0)