1.通过composer 安装库
$ composer require "open-smf/connection-pool:~1.0"
# 该包库只能在swoole 的协程环境下使。
2.引用connection-pool并配置ConnectionPool.php步骤:
use Smf\ConnectionPool\ConnectionPool;
use Smf\ConnectionPool\Connectors\CoroutineMySQLConnector;
use Smf\ConnectionPool\Connectors\PhpRedisConnector;
use Swoole\Coroutine\MySQL;
/**
* 该连接池类 只能在 swoole的协程中使用
*/
trait ConnectionPool
{
use ConnectionPoolTrait;
/**
* 启动mysql连接池对象
*/
public function startMysqlPool(int $minActive=10,int $maxActive=30){
$pool = new ConnectionPool([
'minActive' => $minActive,
'maxActive' => $maxActive,
'maxWaitTime' => 5,
'maxIdleTime' => 20,
'idleCheckInterval' => 10,
]