🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 连接池 只需在协程中使用连接池组件获取连接对象即可。 ``` /** @var ConnectionPool $dbPool */ $db = app()->dbPool->getConnection(); $result = $db->createCommand('select sleep(5)')->queryAll(); $db->release(); // 不手动释放的连接不会归还连接池,会在析构时丢弃 ``` [>> 到 GitHub 查看 DEMO <<](https://github.com/mix-php/mix-skeleton/tree/v2.1/app/Console/Commands/CoroutineCommand.php#L40) ## `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` ## 依赖注入配置 - [beans/database](https://github.com/mix-php/mix-skeleton/tree/v2.1/manifest/beans/database.php) - [beans/redis](https://github.com/mix-php/mix-skeleton/tree/v2.1/manifest/beans/redis.php) ## `Dialer` 拨号器 当连接池内的连接为空或者连接不足时,连接池组件会调用 `dialer` 对象获取新的连接。 >[info] 拨号对象都必须实现 Mix\Pool\DialerInterface 接口。 框架默认提供了两个拨号类,如果需要扩展,用户自行实现 `Mix\Pool\DialerInterface `接口即可,也可继承重写。 - [Database Dialer](https://github.com/mix-php/database/blob/master/src/Pool/Dialer.php) - [Redis Dialer](https://github.com/mix-php/redis/blob/master/src/Pool/Dialer.php)