PHPackages                             utopia-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. [Framework](/categories/framework)
4. /
5. utopia-php/pools

ActiveLibrary[Framework](/categories/framework)

utopia-php/pools
================

A simple library to manage connection pools

1.0.3(3mo ago)9242.5k—4.9%3[1 issues](https://github.com/utopia-php/pools/issues)[2 PRs](https://github.com/utopia-php/pools/pulls)4MITPHPPHP &gt;=8.4

Since Oct 11Pushed 3w ago6 watchersCompare

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

READMEChangelog (10)Dependencies (10)Versions (38)Used By (4)

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

61

—

FairBetter than 99% of packages

Maintenance86

Actively maintained with recent releases

Popularity43

Moderate usage in the ecosystem

Community27

Small or concentrated contributor base

Maturity76

Established project with proven stability

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

Recently: every ~17 days

Total

18

Last Release

103d ago

Major Versions

0.8.3 → 1.0.02026-01-15

PHP version history (3 changes)0.1.0PHP &gt;=8.0

0.6.0PHP &gt;=8.3

0.8.3PHP &gt;=8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/023f08a9df59f81cc4a04b1cebd20f45ede5db53ef2f9e9ad3d75f4c69be66b8?d=identicon)[eldadfux](/maintainers/eldadfux)

---

Top Contributors

[![eldadfux](https://avatars.githubusercontent.com/u/1297371?v=4)](https://github.com/eldadfux "eldadfux (41 commits)")[![ArnabChatterjee20k](https://avatars.githubusercontent.com/u/83803257?v=4)](https://github.com/ArnabChatterjee20k "ArnabChatterjee20k (30 commits)")[![abnegate](https://avatars.githubusercontent.com/u/5857008?v=4)](https://github.com/abnegate "abnegate (28 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)")[![hmacr](https://avatars.githubusercontent.com/u/132386067?v=4)](https://github.com/hmacr "hmacr (4 commits)")[![loks0n](https://avatars.githubusercontent.com/u/22452787?v=4)](https://github.com/loks0n "loks0n (4 commits)")[![claudear](https://avatars.githubusercontent.com/u/262350598?v=4)](https://github.com/claudear "claudear (1 commits)")

---

Tags

hacktoberfestphppoolsutopiaphpframeworkutopiapools

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[utopia-php/cache

A simple cache library to manage application cache storing, loading and purging

31447.6k15](/packages/utopia-php-cache)[utopia-php/framework

A simple, light and advanced PHP HTTP framework

295676.7k11](/packages/utopia-php-framework)[utopia-php/storage

A simple Storage library to manage application storage

30277.2k9](/packages/utopia-php-storage)[utopia-php/queue

A powerful task queue.

11218.6k5](/packages/utopia-php-queue)[utopia-php/http

A simple, light and advanced PHP HTTP framework

29332.7k4](/packages/utopia-php-http)[utopia-php/database

A simple library to manage application persistence using multiple database adapters

74384.6k10](/packages/utopia-php-database)

PHPackages © 2026

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