PHPackages                             nstwf/mysql-connection-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. nstwf/mysql-connection-pool

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

nstwf/mysql-connection-pool
===========================

Reactphp MySQL connection pool

1.2.1(10mo ago)249[3 PRs](https://github.com/nstwfdev/mysql-connection-pool/pulls)MITPHPPHP ^8.1CI passing

Since Dec 22Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/nstwfdev/mysql-connection-pool)[ Packagist](https://packagist.org/packages/nstwf/mysql-connection-pool)[ RSS](/packages/nstwf-mysql-connection-pool/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (3)Versions (10)Used By (0)

ReactPHP MySQL connection pool
==============================

[](#reactphp-mysql-connection-pool)

[![CI](https://camo.githubusercontent.com/ddc4bec9f794100b5b6033b27f88d0df71e69daec7bcbe87436cb696684498e5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6e737477666465762f6d7973716c2d636f6e6e656374696f6e2d706f6f6c2f63692e796d6c3f6272616e63683d6d6173746572266c6162656c3d6369266c6f676f3d676974687562)](https://github.com/nstwfdev/mysql-connection-pool/actions?query=workflow%3Aci+branch%3Amaster)[![codecov](https://camo.githubusercontent.com/78153af304478cdaede884fa3ef67d7ea555360b65b4d9d3609f878c47e42b55/68747470733a2f2f636f6465636f762e696f2f67682f6e737477666465762f6d7973716c2d636f6e6e656374696f6e2d706f6f6c2f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d39594c3946534d345256)](https://codecov.io/gh/nstwfdev/mysql-connection-pool)[![Packagist Version](https://camo.githubusercontent.com/06f79dea2078c1f0b57bb9a20fdcffacbec86b04a9250c024cb2e6648a545613/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e737477662f6d7973716c2d636f6e6e656374696f6e2d706f6f6c3f6c6f676f3d7061636b6167697374)](https://packagist.org/packages/nstwf/mysql-connection-pool)

Simple connection pool for [mysql client](https://github.com/friends-of-reactphp/mysql) using [connection](https://github.com/nstwfdev/mysql-connection)

**Table of contents**

- [Quickstart example](#quickstart-example)
- [Usage](#usage)
    - [PoolInterface](#poolinterface)
        - [Options](#options)
        - [getConnection()](#getconnection)
        - [releaseConnection()](#releaseconnection)
        - [query()](#query)
        - [transaction()](#transaction)
- [Install](#install)
- [Tests](#tests)
- [License](#license)

Quickstart example
------------------

[](#quickstart-example)

```
$pool = new \Nstwf\MysqlConnectionPool\Pool('localhost:3306');

$pool
    ->getConnection()
    ->then(function (\Nstwf\MysqlConnection\ConnectionInterface $connection) use ($pool) {
        $connection->query("UPDATE users SET blocked = 1 WHERE id = 3");

        $pool->releaseConnection($connection);
    });
```

Usage
-----

[](#usage)

### PoolInterface

[](#poolinterface)

The main role of `PoolInterface` - managing connections with selected options

#### Options

[](#options)

- `waitForConnections: bool`, set up the behavior while no free connections exists and user call `getConnection` method. If set to `false` - throws an exception, otherwise return a promise with free connection. (Default: `true`)
- `connectionLimit: int`, the maximum number of connections at the same time. `0` - for unlimited. (Default: `5`)

```
$pool = new \Nstwf\MysqlConnectionPool\Pool('localhost:3306', null, 10, false);
```

#### getConnection

[](#getconnection)

The `getConnection(): PromiseInterface` method can be used to create a new `ConnectionInterface` instance if no free connections available, otherwise select one of free

```
$pool
    ->getConnection()
    ->then(function (\Nstwf\MysqlConnection\ConnectionInterface $connection) {
       $connection->query("UPDATE users SET active = 0 WHERE id = 2");
       $connection->query("UPDATE users SET blocked = 1 WHERE id = 3");

       $pool->releaseConnection($connection);
    });
```

#### releaseConnection

[](#releaseconnection)

The `releaseConnection(ConnectionInterface $connection): void` method can be used to release connection to the pool

```
$pool->releaseConnection($connection);
```

#### query

[](#query)

The `query(string $sql, array $params = []): PromiseInterface` method is a shortcut for calls `getConnection()` -&gt; `query()` -&gt; `releaseConnection()`

```
$pool->query("UPDATE users SET active = 0 WHERE id = ?", [2]);
```

#### transaction

[](#transaction)

The `transaction(callable $callable): PromiseInterface` method is a shortcut for calls: `getConnection()` -&gt; `transaction()` -&gt; `releaseConnection()`:

```
$pool->transaction(function(\Nstwf\MysqlConnection\ConnectionInterface $connection) {
    $connection->query("UPDATE users SET active = 0 WHERE id = 2");
});
```

Install
-------

[](#install)

The recommended way to install this library is [through Composer](https://getcomposer.org). [New to Composer?](https://getcomposer.org/doc/00-intro.md)

This project follows [SemVer](https://semver.org/). This will install the latest supported version:

```
composer require nstwf/mysql-connection-pool
```

See also the [CHANGELOG](docs/CHANGELOG.md) for details about version upgrades.

It's *highly recommended to use PHP 8+* \* for this project.

Tests
-----

[](#tests)

To run the test suite, you first need to clone this repo and then install all dependencies [through Composer](https://getcomposer.org):

```
composer install
```

To run the test suite, go to the project root and run:

```
vendor/bin/phpunit
```

License
-------

[](#license)

MIT, see [LICENSE file](LICENSE).

- [friends-of-reactphp/mysql](https://github.com/friends-of-reactphp/mysql) - main project
- [mysqljs/mysql](https://github.com/mysqljs/mysql) - main concept

###  Health Score

41

—

FairBetter than 88% of packages

Maintenance74

Regular maintenance activity

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 90.3% 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 ~186 days

Recently: every ~233 days

Total

6

Last Release

301d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6d1c9e30d7385c8913697b4c80e5cc75cfb2cba78abc541dc13cdc2a127ad412?d=identicon)[nstwf](/maintainers/nstwf)

---

Top Contributors

[![nstwfdev](https://avatars.githubusercontent.com/u/77036413?v=4)](https://github.com/nstwfdev "nstwfdev (28 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")

---

Tags

connectionconnection-poolmysqlphpreactphp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nstwf-mysql-connection-pool/health.svg)

```
[![Health](https://phpackages.com/badges/nstwf-mysql-connection-pool/health.svg)](https://phpackages.com/packages/nstwf-mysql-connection-pool)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.3k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M542](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M209](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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