PHPackages                             flyokai/laminas-db-driver-async - 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. flyokai/laminas-db-driver-async

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

flyokai/laminas-db-driver-async
===============================

Async driver for laminas db

0.1.0(1mo ago)05↓100%MITPHPPHP ^8.1

Since Apr 25Pushed 2w agoCompare

[ Source](https://github.com/flyokai/laminas-db-driver-async)[ Packagist](https://packagist.org/packages/flyokai/laminas-db-driver-async)[ RSS](/packages/flyokai-laminas-db-driver-async/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (3)Versions (6)Used By (0)

flyokai/laminas-db-driver-async
===============================

[](#flyokailaminas-db-driver-async)

> User docs → [`README.md`](README.md) · Agent quick-ref → [`CLAUDE.md`](CLAUDE.md) · Agent deep dive → [`AGENTS.md`](AGENTS.md)

> Two-strategy async database driver for Laminas DB: **AsyncPdo** (AMPHP worker pools, process-isolated) and **AsyncMysqli** (Revolt event loop + `MYSQLI_ASYNC`, in-process cooperative).

Pick whichever fits your workload — both implement Laminas DB's `DriverInterface`. AsyncMysqli is the default `ConnectionPool` in Flyokai.

Features
--------

[](#features)

- **AsyncPdo** — strong process isolation via AMPHP `Parallel` workers (default 32). True server-side prepared statements.
- **AsyncMysqli** — in-process cooperative concurrency via `MYSQLI_ASYNC` and `EventLoop::onMysqli()`. Auto-retry on connection errors and deadlocks.
- **`ConnectionPool`** interface — factory contract used by Flyokai's `AmpConnectionPool`, `AsyncPdoConnectionPool`, `AsyncMysqliConnectionPool`
- **FiberLocal state** — transaction level / pdo resource isolated per fiber
- **`CreateSqlTrait`** — convenience for building Laminas `Sql` instances from pool connections

Installation
------------

[](#installation)

```
composer require flyokai/laminas-db-driver-async
```

When to use which
-----------------

[](#when-to-use-which)

AspectAsyncPdoAsyncMysqliIsolationStrong (separate processes)Weak (same process)OverheadHigher (serialization, IPC)Lower (in-process)StatementsTrue server-side preparedClient-side parameter interpolationScalabilityCPU-bound workI/O-bound workTransactionsFull nesting via level trackingBasic begin/commit/rollbackFiber-aware state`FiberLocal`Implicit via the event loopAsyncPdo
--------

[](#asyncpdo)

### Architecture

[](#architecture)

```
PdoTask (serializable) ──► PooledWorker.execute()
                            ▼
                       Worker process
                       LocalCache[pdoId] → PDO/PDOStatement
                       returns scalar result

```

### Quick start

[](#quick-start)

```
use Flyokai\LaminasDbDriverAsync\AsyncPdo\PdoWorkerPool;
use Flyokai\LaminasDbDriverAsync\AsyncPdo\Connection;

$pool       = new PdoWorkerPool(workerLimit: 32);
$connection = new Connection($pool, [
    'dsn'      => 'mysql:host=localhost;dbname=app',
    'username' => 'app',
    'password' => 'secret',
]);

// Use $connection through Laminas DB exactly as you'd use a sync PDO connection.
```

`PdoTask` operations: `connect`, `execute`, `prepare`, `statement:execute`, `statement:fetch`, `statement:fetchAll`, … each routes to a cached PDO/PDOStatement in the worker via `spl_object_id()`.

AsyncMysqli
-----------

[](#asyncmysqli)

### Architecture

[](#architecture-1)

```
$mysqli->query($sql, MYSQLI_ASYNC);
EventLoop::onMysqli($link, fn() => $suspension->resume($link->reap_async_query()));
$result = $suspension->suspend();

```

### Quick start

[](#quick-start-1)

```
use Flyokai\LaminasDbDriverAsync\AsyncMysqli\LinkPool;
use Flyokai\LaminasDbDriverAsync\AsyncMysqli\Connection;

$pool       = new LinkPool($factory, max: 32);
$connection = new Connection($pool);
```

The `Connection` delegates to `ParentConnection` for raw mysqli operations and adds `queryWithRetry()`:

- Automatic reconnect on errors `2006` (gone away) and `2013` (lost during query)
- Retry on deadlock `1213`
- Up to 10 retries

### Parameter binding

[](#parameter-binding)

There are no prepared statements — parameters are interpolated client-side via `Platform::quoteValue()`. Named parameters are sorted by length (longest first) to avoid partial replacement.

In Flyokai
----------

[](#in-flyokai)

`AsyncMysqliConnectionPool` is the **default** `ConnectionPool` configured via the DI alias in the application's `diconfig.php`. Switch to `AsyncPdoConnectionPool` or `AmpConnectionPool` by overriding the alias.

Gotchas
-------

[](#gotchas)

- **`PendingOperationError` (PDO)** — cannot start a new operation while another is in flight on the same resource. Await before issuing the next call.
- **`fiber_mode=true`** isolates state per fiber. `fiber_mode=false` shares global state — race-condition risk.
- **Process serialization (PDO)** — only scalars and arrays cross worker boundaries. Closures, resources, complex objects don't.
- **No prepared statements (MySQLi)** — parameters are interpolated. Safety relies entirely on `quoteValue()`.
- **Pool starvation** — if all workers/links are occupied, subsequent requests block until one returns.
- **Auto-retry hides failures (MySQLi)** — connection errors and deadlocks are retried up to 10 times before giving up.
- **Worker cache pollution (PDO)** — `LocalCache` in workers persists across executions. Long-running workers may leak memory if you forget to release statements.
- **Requires active EventLoop** — both strategies need a Revolt event loop context.

See also
--------

[](#see-also)

- [`flyokai/laminas-db`](../laminas-db/README.md) — base abstraction
- [`flyokai/laminas-db-driver-amp`](../laminas-db-driver-amp/README.md) — alternative driver using `amphp/mysql`
- [`flyokai/revolt-event-loop`](../revolt-event-loop/README.md) — `onMysqli()` is the AsyncMysqli primitive
- [`flyokai/application`](../application/README.md) — wires the connection pools into DI

License
-------

[](#license)

MIT

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance94

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 80% 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 ~0 days

Total

2

Last Release

44d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/247743048?v=4)[flyokai](/maintainers/flyokai)[@flyokai](https://github.com/flyokai)

---

Top Contributors

[![flyokai](https://avatars.githubusercontent.com/u/247743048?v=4)](https://github.com/flyokai "flyokai (4 commits)")[![wtsergo](https://avatars.githubusercontent.com/u/305326?v=4)](https://github.com/wtsergo "wtsergo (1 commits)")

### Embed Badge

![Health badge](/badges/flyokai-laminas-db-driver-async/health.svg)

```
[![Health](https://phpackages.com/badges/flyokai-laminas-db-driver-async/health.svg)](https://phpackages.com/packages/flyokai-laminas-db-driver-async)
```

###  Alternatives

[phpro/grumphp

A composer plugin that enables source code quality checks.

4.3k16.3M972](/packages/phpro-grumphp)[vimeo/psalm

A static analysis tool for finding errors in PHP applications

5.9k80.5M7.4k](/packages/vimeo-psalm)[danog/madelineproto

Async PHP client API for the telegram MTProto protocol.

3.4k885.1k21](/packages/danog-madelineproto)[amphp/mysql

Asynchronous MySQL client for PHP based on Amp.

3761.1M33](/packages/amphp-mysql)[amphp/file

Non-blocking access to the filesystem based on Amp and Revolt.

1103.4M118](/packages/amphp-file)[amphp/postgres

Asynchronous PostgreSQL client for Amp.

110557.2k35](/packages/amphp-postgres)

PHPackages © 2026

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