24 lines
686 B
PHP
24 lines
686 B
PHP
<?php
|
|
require __DIR__."/vendor/autoload.php";
|
|
|
|
go(function (){
|
|
$pool = new \baihand\pool\CoMySqlPool();
|
|
$pool->initPool();
|
|
for ($i = 0; $i < 5; $i++) {
|
|
go(function () use($pool,$i) {
|
|
$conn = $pool->getConnection();
|
|
defer(function () use ($pool,$conn){
|
|
//defer写在前 是怕后面的执行语句不一定成功
|
|
$pool->close($conn); // 放回链接
|
|
//channel对connection进行了引用
|
|
});
|
|
$state = $conn->query(" select $i");
|
|
|
|
var_dump($state);
|
|
});
|
|
}
|
|
while (true){
|
|
echo "链接了\n";
|
|
\Swoole\Coroutine::sleep(1);
|
|
}
|
|
}); |