PHPackages                             tourze/php-pools - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. tourze/php-pools

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

tourze/php-pools
================

A simple library to manage connection pools

0.0.2(1y ago)02651MITPHPPHP ^8.1CI passing

Since Apr 24Pushed 5mo agoCompare

[ Source](https://github.com/tourze/php-pools)[ Packagist](https://packagist.org/packages/tourze/php-pools)[ RSS](/packages/tourze-php-pools/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (4)Used By (1)

Utopia Pools
============

[](#utopia-pools)

[![Build Status](https://camo.githubusercontent.com/1289e1a8572819b663fbdfb0a04a54039a0d73df25f4d04ba3d3505c8c4e44d4/68747470733a2f2f7472617669732d63692e636f6d2f75746f7069612d7068702f706f6f6c732e7376673f6272616e63683d6d61696e)](https://travis-ci.com/utopia-php/pools)[![Total Downloads](https://camo.githubusercontent.com/cc53939ef65eb77e9cbcfd99f8ae449da11935270794ba23fe9e55386177e1ec/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f75746f7069612d7068702f706f6f6c732e737667)](https://camo.githubusercontent.com/cc53939ef65eb77e9cbcfd99f8ae449da11935270794ba23fe9e55386177e1ec/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f75746f7069612d7068702f706f6f6c732e737667)[![Discord](https://camo.githubusercontent.com/6e418910df1b6eb524c6cbd88dbaf5a5aa294316eeadcd963e11262a319f6321/68747470733a2f2f696d672e736869656c64732e696f2f646973636f72642f3536343136303733303834353135313234343f6c6162656c3d646973636f7264)](https://appwrite.io/discord)

Utopia pools library is simple and lite library for managing long living connection pools. This library is aiming to be as simple and easy to learn and use. This library is maintained by the [Appwrite team](https://appwrite.io).

Although this library is part of the [Utopia Framework](https://github.com/utopia-php/framework) project it is dependency free, and can be used as standalone with any other PHP project or framework.

Concepts
--------

[](#concepts)

- **Pool** - A list of long living connections. You can pop connections out and use them and push them back to the pool for reuse.
- **Connection** - An object that holds a long living database or other external connection in a form of a resource. PDO object or a Redis client are examples of resources that can be used inside a connection.
- **Group** - A group of multiple pools.

Getting Started
---------------

[](#getting-started)

Install using composer:

```
composer require utopia-php/pools
```

Examples
--------

[](#examples)

```
use PDO;
use Utopia\Pools\Pool;
use Utopia\Pools\Group;

$pool = new Pool('mysql-pool', 1 /* number of connections */, function() {
    $host = '127.0.0.1';
    $db   = 'test';
    $user = 'root';
    $pass = '';
    $charset = 'utf8mb4';

    try {
        $pdo = new PDO("mysql:host=$host;dbname=$db;charset=$charset", $user, $pass);
    } catch (\PDOException $e) {
        throw new \PDOException($e->getMessage(), (int)$e->getCode());
    }

    return $pdo;
});

$pool->setReconnectAttempts(3); // number of attempts to reconnect
$pool->setReconnectSleep(5); // seconds to sleep between reconnect attempts

$pool->setRetryAttempts(3); // number of attempts to get connection
$pool->setRetrySleep(5); // seconds to sleep between failed pop-connection attempts

$connection = $pool->pop(); // Get a connection from the pool
$connection->getID(); // Get the connection ID
$connection->getResource(); // Get the connection resource

$pool->push($connection); // Return the connection to the pool

$pool->reclaim(); // Recalim the pool, return all active connections automatically

$pool->count(); // Get the number of available connections

$pool->isEmpty(); // Check if the pool is empty

$pool->isFull(); // Check if the pool is full

$group = new Group(); // Create a group of pools
$group->add($pool); // Add a pool to the group
$group->get('mysql-pool'); // Get a pool from the group
$group->setReconnectAttempts(3); // Set the number of reconnect attempts for all pools
$group->setReconnectSleep(5); // Set the sleep time between reconnect attempts for all pools
```

Reconnect and Retry
-------------------

[](#reconnect-and-retry)

Both reconnect and retry logic is used in `pop()` method to handle problematic scenarios. Both allow you to configure 2 properties:

- `attempts` - How many times library will retry when problem occurs
- `sleep` - How long will library wait for before next retry attempt

**Reconnect** settings are used when your connection initialization callback throws an exception. This can occur for example, when a handshake with SQL server fails.

**Retry** settings are used when pool of connection is empty and there is no more connections to pop. This can occur for example, when your server supports more concurrent actions than your pool.

System Requirements
-------------------

[](#system-requirements)

Utopia Framework requires PHP 8.0 or later. We recommend using the latest PHP version whenever possible.

Tests
-----

[](#tests)

To run all unit tests, use the following Docker command:

```
docker compose exec tests vendor/bin/phpunit --configuration phpunit.xml tests
```

To run static code analysis, use the following Psalm command:

```
docker compose exec tests vendor/bin/psalm --show-info=true
```

Copyright and license
---------------------

[](#copyright-and-license)

The MIT License (MIT)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance62

Regular maintenance activity

Popularity12

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~0 days

Total

2

Last Release

390d ago

### Community

Maintainers

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

---

Top Contributors

[![eldadfux](https://avatars.githubusercontent.com/u/1297371?v=4)](https://github.com/eldadfux "eldadfux (41 commits)")[![abnegate](https://avatars.githubusercontent.com/u/5857008?v=4)](https://github.com/abnegate "abnegate (18 commits)")[![Meldiron](https://avatars.githubusercontent.com/u/19310830?v=4)](https://github.com/Meldiron "Meldiron (17 commits)")[![christyjacob4](https://avatars.githubusercontent.com/u/20852629?v=4)](https://github.com/christyjacob4 "christyjacob4 (7 commits)")[![basert](https://avatars.githubusercontent.com/u/1951610?v=4)](https://github.com/basert "basert (5 commits)")

---

Tags

phputopiapools

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-php-pools/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-php-pools/health.svg)](https://phpackages.com/packages/tourze-php-pools)
```

###  Alternatives

[utopia-php/messaging

A simple, light and advanced PHP messaging library

23187.5k4](/packages/utopia-php-messaging)[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21421.6k](/packages/imanghafoori-laravel-anypass)

PHPackages © 2026

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