File tree 7 files changed +20
-15
lines changed
7 files changed +20
-15
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ $db->addConnection([
41
41
'max_connections' => 10, // max 10 connection
42
42
'max_wait_queue' => 110, // how many sql in queue
43
43
'wait_timeout' => 5,// wait time include response time
44
- 'keep_alive ' => 10 , //
44
+ 'idle ' => 60 , //
45
45
]
46
46
]);
47
47
Original file line number Diff line number Diff line change 11
11
],
12
12
"require" : {
13
13
"php" : " ^8.1" ,
14
- "reactphp-x/mysql-pool" : " ^1.0" ,
15
14
"react/async" : " ^4 || ^3 || ^2" ,
16
- "illuminate/database" : " ^11.19"
15
+ "illuminate/database" : " ^11.19" ,
16
+ "reactphp-x/mysql-pool" : " ^2.0@dev"
17
17
},
18
18
"autoload" : {
19
19
"psr-4" : {
20
20
"ReactphpX\\ Orm\\ " : " src"
21
21
}
22
- }
22
+ },
23
+ "minimum-stability" : " dev" ,
24
+ "prefer-stable" : true
23
25
}
Original file line number Diff line number Diff line change 31
31
});
32
32
33
33
print_r (DB ::getQueryLog ());
34
- DB ::disconnect ();
34
+ // DB::disconnect();
35
35
36
36
37
37
Original file line number Diff line number Diff line change 22
22
// true
23
23
var_dump (DB ::table ('test_users ' )->where ('name ' , 'test-failed ' )->count () === 0 );
24
24
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;
27
27
28
28
// success
29
29
DB ::table ('test_users ' )->where ('name ' , 'test-success ' )->delete ();
40
40
// true
41
41
var_dump (DB ::table ('test_users ' )->where ('name ' , 'test-success ' )->count () === 1 );
42
42
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;
45
45
46
46
47
47
DB ::disconnect ();
Original file line number Diff line number Diff line change 30
30
'max_connections ' => 10 , // max 10 connection
31
31
'max_wait_queue ' => 110 , // how many sql in queue
32
32
'wait_timeout ' => 5 ,// wait time include response time
33
- 'keep_alive ' => 10 , //
33
+ 'idle ' => 60 , //
34
34
]
35
35
]);
36
36
@@ -186,8 +186,8 @@ public function posts()
186
186
187
187
\React \EventLoop \Loop::addPeriodicTimer (1 , function () {
188
188
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;
191
191
} else {
192
192
var_dump ('pool closed ' );
193
193
\React \EventLoop \Loop::stop ();
Original file line number Diff line number Diff line change @@ -339,7 +339,7 @@ public function beginTransaction()
339
339
throw new Exception ("had in transaction " );
340
340
}
341
341
342
- $ connection = \React \Async \await ($ this ->getPdo ()->getIdleConnection ());
342
+ $ connection = \React \Async \await ($ this ->getPdo ()->getConnection ());
343
343
\React \Async \await ($ connection ->query ('BEGIN ' ));
344
344
$ db = clone $ this ;
345
345
$ db ->setPdo ($ connection );
Original file line number Diff line number Diff line change @@ -28,8 +28,11 @@ public function connect($config)
28
28
$ database = $ config ['database ' ];
29
29
30
30
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 ,
33
36
);
34
37
}
35
38
}
You can’t perform that action at this time.
0 commit comments