snapflowio/pooling
最新稳定版本:v0.1.0
Composer 安装命令:
composer require snapflowio/pooling
包简介
A simple and lightweight library to manage long lived connection pools.
README 文档
README
A simple and lightweight library to manage long lived connection pools.
Installation
composer require snapflow/pooling
Quick Start
<?php use Snapflow\Pooling\Pooling; // Create a connection pool $pool = new Pooling( name: 'database', size: 10, init: fn () => new PDO('mysql:host=localhost;dbname=mydb', 'user', 'pass') ); // Use a connection with automatic lifecycle management $result = $pool->use(function (PDO $pdo) { $stmt = $pdo->prepare('SELECT * FROM users WHERE id = ?'); $stmt->execute([1]); return $stmt->fetch(); }); // Configure retry/reconnect behavior $pool ->setRetryAttempts(5) // Retry 5 times if pool is empty ->setRetrySleep(2) // Wait 2 seconds between retries ->setReconnectAttempts(3) // Retry 3 times if connection fails ->setReconnectSleep(1); // Wait 1 second between reconnects // Monitor pool health $stats = $pool->getStats(); // Returns: ['name', 'size', 'available', 'active', 'idle', 'uninitialized'] // Optional: Cleanup resources when connections are destroyed $poolWithCleanup = new Pooling( name: 'redis', size: 5, init: fn () => new Redis(), cleanup: fn (Redis $redis) => $redis->close() );
License
This library is available under the MIT License.
Copyright
Copyright (c) 2025 Snapflow
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-15