原标题:基于Swoole的通用连接池 - 数据库连接池
连接池
open-smf/connection-pool 是一个基于Swoole的通用连接池,常被用作数据库连接池。
依赖
依赖
版本
PHP
>=7.0.0
Swoole
>=4.2.9 Recommend 4.2.13+安装
通过 Composer 安装。
composer require "open-smf/connection-pool:~1.0" 使用
更多 示例 。
基本用法use SmfConnectionPoolConnectionPool;
use SmfConnectionPoolConnectorsCoroutineMySQLConnector;
use SwooleCoroutineMySQL;
go(function () {
// MySQL连接数区间:[10, 30]
$pool = new ConnectionPool(
[
'minActive' => 10,
'maxActive' => 30,
'maxWaitTime' => 5,
'maxIdleTime' => 20,
'idleCheckInterval' => 10,
],
new CoroutineMySQLConnector, // 指明连接器实例,这里使用协程MySQL连接器,这样就可以创建一个协程MySQL的数据库连接池
[
'host' => '127.0.0.1',
'port' => '3306',
'user' => 'root',
'password' => 'xy123456',
'database' => 'mysql',
'timeout' => 10,
'charset' => 'utf8mb4',
'strict_type'