PHP code example of raylin666 / pool
1. Go to this page and download the library: Download raylin666/pool library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
raylin666 / pool example snippets
aylin666\Pool\SimplePool;
use Raylin666\Pool\PoolConfig;
use Raylin666\Pool\PoolOption;
$poolConfig = new PoolConfig(
'database',
function () {
// 一般返回连接对象, 例如: return new PDO(...);
return 'mysql';
},
(new PoolOption())
->withMinConnections(10)
->withMaxConnections(100)
);
/**
* 扩展提供了 SimplePool 和 SimpleConnection 类可以直接使用简单的连接池.
* 也可以继承 Pool 和 Connection, 实现相对复杂的业务连接池
*/
$pool = new \Raylin666\Pool\SimplePool($poolConfig); // 创建连接池
$conn = $pool->get(); // 获取连接
$conn->getConnection(); // 获取连接内容, 即连接对象
$conn->release(); // 连接发布(放回连接池)
var_dump($pool);