Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/szado/php-resource-pool
A PHP library providing resource pooling support, commonly used as a database connection pool.
https://github.com/szado/php-resource-pool
connection-manager connection-pool php reactphp
Last synced: 3 months ago
JSON representation
A PHP library providing resource pooling support, commonly used as a database connection pool.
- Host: GitHub
- URL: https://github.com/szado/php-resource-pool
- Owner: szado
- Created: 2021-12-03T22:48:24.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-10-05T17:49:50.000Z (4 months ago)
- Last Synced: 2024-10-31T22:21:55.453Z (3 months ago)
- Topics: connection-manager, connection-pool, php, reactphp
- Language: PHP
- Homepage:
- Size: 62.5 KB
- Stars: 8
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# shado/php-resource-pool
A PHP library providing resource pooling support, commonly used as a database connection pool.
Resource pooling allows you to easily manage a range of concurrently maintained resources. You can define how many of them can be created or which algorithm should be used for selecting the next resource from the pool.
The library includes two implementations of the pool:
- `ResourcePool` – provides basic pooling logic, including borrowing and returning resources.
- `AsyncResourcePool` – a [ReactPHP](https://reactphp.org/)-based implementation that adds resource retry functionality to the basic features.## Requirements
- PHP >= 8.1
> [!TIP]
> Thanks to Fibers, you can freely use the ReactPHP-based implementation in your traditional PHP projects.## Example
```php
$factory = function (\Shado\ResourcePool\FactoryController $controller) {
$newConnection = new DbConnection();
$newConnection->onClose($controller->detach(...)); // When connection closes, detach it from the pool
return $newConnection;
};$pool = new \Shado\ResourcePool\ResourcePool($factory, 10);
$connection = $pool->borrow(); // `$connection` is ready to use :)
// $connection->query(...);
$pool->return($connection);
```## At the end...
- Run tests: `./vendor/bin/phpunit tests`.
- Feel free to create an issue or submit your PR! 🤗
- Licence: MIT.