多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## 连接池 只需在协程中使用连接池组件获取连接对象即可。 ``` $db = app()->dbPool->getConnection(); $result = $db->createCommand('select sleep(5)')->queryAll(); $db->release(); // 不手动释放的连接不会归还连接池,会在析构时丢弃 ``` [>> 到 GitHub 查看 DEMO <<](https://github.com/mix-php/mix/blob/v2/applications/console/src/Commands/CoroutineCommand.php#L39) ## `Mix\Pool\AbstractConnectionPool` 所有的连接池对象都继承该抽象类,框架提供了 db, redis 两个封装好的连接池类: - [DB](https://github.com/mix-php/mix-database/tree/master/src/Pool):`Mix\Database\Pool\ConnectionPool::class` - [Redis](https://github.com/mix-php/mix-redis/tree/master/src/Pool):`Mix\Redis\Pool\ConnectionPool::class` ## 依赖注入配置 [>> 到 GitHub 查看默认配置 <<](https://github.com/mix-php/mix/blob/v2/applications/console/config/main.php#L141) ## `Dialer` 拨号器 当连接池内的连接为空或者连接不足时,连接池组件会调用 `dialer` 对象获取新的连接。 >[info] 拨号对象都必须实现 Mix\Pool\DialerInterface 接口。 框架默认提供了两个拨号类,默认拨号类代码为通过依赖注入实例化协程连接对象,如果需要扩展,用户自行实现 `Mix\Pool\DialerInterface `接口即可。 - [DatabaseDialer](https://github.com/mix-php/mix/blob/v2/applications/common/src/Libraries/Dialers/DatabaseDialer.php) - [RedisDialer](https://github.com/mix-php/mix/blob/v2/applications/common/src/Libraries/Dialers/RedisDialer.php)