PHPackages                             shado/php-resource-pool - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. shado/php-resource-pool

ActiveLibrary[Database &amp; ORM](/categories/database)

shado/php-resource-pool
=======================

A PHP library providing resource pooling support, commonly used as a database connection pool.

v0.3.0(9mo ago)19482MITPHPPHP &gt;=8.1

Since Dec 12Pushed 9mo ago2 watchersCompare

[ Source](https://github.com/szado/php-resource-pool)[ Packagist](https://packagist.org/packages/shado/php-resource-pool)[ RSS](/packages/shado-php-resource-pool/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (4)Versions (8)Used By (0)

shado/php-resource-pool
=======================

[](#shadophp-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.

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
------------

[](#installation)

You can install the library using Composer:

```
composer require shado/php-resource-pool
```

Requirements
------------

[](#requirements)

- PHP &gt;= 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](https://reactphp.org/).

Example
-------

[](#example)

### Basic usage of the `ResourcePool`

[](#basic-usage-of-the-resourcepool)

```
$factory = function (\Shado\ResourcePool\FactoryController $controller) {
    $newConnection = new DbConnection();
    $newConnection->onClose($controller->detach(...));
    $newConnection->onError($controller->detach(...));
    return $newConnection;
};

$pool = new \Shado\ResourcePool\ResourcePool($factory, limit: 10);

$connection = $pool->borrow(); // `$connection` is ready to use :)

try {
// $connection->query(...);
} finally {
    $pool->return($connection);
}
```

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`

[](#using-the-retry-functionality-with-asyncresourcepool)

```
$factory = function (\Shado\ResourcePool\FactoryController $controller) {
    $newConnection = new DbConnection();
    $newConnection->onClose($controller->detach(...));
    $newConnection->onError($controller->detach(...));
    return $newConnection;
};

$pool = new \Shado\ResourcePool\AsyncResourcePool(
    new \Shado\ResourcePool\ResourcePool($factory, limit: 10),
    retryingTimeout: null,
    retryingDelay: 0.01
);

$connection = $pool->borrow(); // `$connection` is ready to use :)
// ...or you can make use of the Promise:
// $connection = \React\Async\await($pool->borrowAsync());

try {
    // $connection->query(...);
} finally {
    $pool->return($connection);
}
```

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...
-------------

[](#at-the-end)

- Run tests: `./vendor/bin/phpunit tests`.
- Feel free to create an issue or submit your PR! 🤗
- Licence: MIT.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance57

Moderate activity, may be stable

Popularity19

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 85.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~101 days

Total

4

Last Release

288d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a9670f1019613ef199e28de11cef0fb3320967b0004e2b4214cdba3db4ebd55c?d=identicon)[szado](/maintainers/szado)

---

Top Contributors

[![szado](https://avatars.githubusercontent.com/u/20907536?v=4)](https://github.com/szado "szado (30 commits)")[![czlowiekpolar](https://avatars.githubusercontent.com/u/45788990?v=4)](https://github.com/czlowiekpolar "czlowiekpolar (4 commits)")[![iorsa](https://avatars.githubusercontent.com/u/32541698?v=4)](https://github.com/iorsa "iorsa (1 commits)")

---

Tags

connection-managerconnection-poolphpreactphp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/shado-php-resource-pool/health.svg)

```
[![Health](https://phpackages.com/badges/shado-php-resource-pool/health.svg)](https://phpackages.com/packages/shado-php-resource-pool)
```

###  Alternatives

[ccxt/ccxt

A cryptocurrency trading API with more than 100 exchanges in JavaScript / TypeScript / Python / C# / PHP / Go

41.5k328.9k1](/packages/ccxt-ccxt)[team-reflex/discord-php

An unofficial API to interact with the voice and text service Discord.

1.1k379.4k24](/packages/team-reflex-discord-php)[league/geotools

Geo-related tools PHP 7.3+ library

1.4k5.3M26](/packages/league-geotools)[clue/redis-react

Async Redis client implementation, built on top of ReactPHP.

28210.5M45](/packages/clue-redis-react)[rector/rector-src

Instant Upgrade and Automated Refactoring of any PHP code

134391.5k12](/packages/rector-rector-src)[react/mysql

Async MySQL database client for ReactPHP.

340421.0k29](/packages/react-mysql)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
