基于Swoole的通用连接池 - 数据库连接池
由 hhxsv5 创建于1年前, 最后更新于 1年前
版本号 #1
6239 views
3 likes
0 collects
连接池
open-smf/connection-pool 是一个基于Swoole的通用连接池,常被用作数据库连接池。
依赖
依赖
版本>=7.0.0
>=4.2.9 Recommend 4.2.13+
安装
composer require "open-smf/connection-pool:~1.0"
使用
更多示例。
可用的连接器连接器
说明CoroutineMySQLConnector
Swoole\Coroutine\MySQL的实例
CoroutinePostgreSQLConnector
Swoole\Coroutine\PostgreSQL的实例,编译Swoole时需要添加参数--enable-coroutine-postgresql
CoroutineRedisConnector
Swoole\Coroutine\Redis的实例
PhpRedisConnector
Redis的实例,需要安装redis
YourConnector
YourConnector必须实现接口ConnectorInterface,任何对象均可作为连接实例基本用法use Smf\ConnectionPool\ConnectionPool;
use Smf\ConnectionPool\Connectors\CoroutineMySQLConnector;
use Swoole\Coroutine\MySQL;
go(function () {
// MySQL连接数区间:[10, 30]
$pool = new ConnectionPool(
[
'minActive' => 10,
'maxActive' => 30,
'maxWaitTime' => 5,
'maxIdleTime' => 20,
'idleCheckInterval' => 10,
],
new CoroutineMySQLConnector, // 指明连接器实例,这里使用协程MySQL连接器,这样就可以创建一个协程MySQL的数据库连接池
[
'ho