Download the PHP package shado/php-resource-pool without Composer
On this page you can find all versions of the php package shado/php-resource-pool. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download shado/php-resource-pool
More information about shado/php-resource-pool
Files in shado/php-resource-pool
Package php-resource-pool
Short Description A PHP library providing resource pooling support, commonly used as a database connection pool.
License MIT
Informations about the package php-resource-pool
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-based implementation that adds resource retry functionality to the basic features.
This library is resource-agnostic, meaning you can use it with any type of resource, such as database connections, file handles, or network sockets.
Installation
You can install the library using Composer:
Requirements
- PHP >= 8.1
[!TIP] Thanks to Fibers, you can freely use the ReactPHP-based implementation in your traditional PHP projects.
New to ReactPHP? Check out the ReactPHP documentation.
Example
Basic usage of the ResourcePool
The factory function is responsible for creating new resources. It receives a FactoryController which can be used to detach the resource from the pool (e.g., when it closes or an error occurs).
In this example, the pool lazily creates new resources using the factory function and limits the number of concurrently maintained resources to 10.
If all resources are in use, the borrow
method throws an Shado\ResourcePool\Exceptions\ResourceSelectingException
.
Using the retry functionality with AsyncResourcePool
After wrapping the ResourcePool
with the AsyncResourcePool
, you can use the retry functionality.
If all resources are in use, the borrow
method waits up to the specified retryingTimeout
(or indefinitely if set to null
)
and retry borrowing a resource after the specified retryingDelay
.
At the end...
- Run tests:
./vendor/bin/phpunit tests
. - Feel free to create an issue or submit your PR! 🤗
- Licence: MIT.
All versions of php-resource-pool with dependencies
react/event-loop Version ^1.5
react/promise Version ^3.2
react/async Version ^4.3