PHPackages                             bear/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. [Queues &amp; Workers](/categories/queues)
4. /
5. bear/async

ActiveLibrary[Queues &amp; Workers](/categories/queues)

bear/async
==========

Async/parallel resource execution library for BEAR.Sunday

0.1.0(3mo ago)10MITPHPPHP ^8.2CI passing

Since Jan 26Pushed 3mo agoCompare

[ Source](https://github.com/bearsunday/BEAR.Async)[ Packagist](https://packagist.org/packages/bear/async)[ RSS](/packages/bear-async/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (4)Used By (0)

BEAR.Async
==========

[](#bearasync)

Async/parallel resource execution library for BEAR.Sunday

Why BEAR.Async?
---------------

[](#why-bearasync)

Unlike traditional async programming (async/await, Promise, yield), BEAR.Async requires **no code changes**. Your existing `#[Embed]` attributes automatically execute in parallel - just install a module.

```
#[Embed(rel: 'profile', src: 'app://self/user/profile?id={user_id}')]
#[Embed(rel: 'posts', src: 'app://self/user/posts?user_id={user_id}')]
#[Embed(rel: 'notifications', src: 'app://self/notifications?user_id={user_id}')]
public function onGet(int $user_id): static
```

These 3 embeds execute **in parallel** instead of sequentially.

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

[](#installation)

```
composer require bear/async
```

Usage
-----

[](#usage)

### Parallel Module (ext-parallel)

[](#parallel-module-ext-parallel)

Recommended for typical web applications with embedded resources.

```
use BEAR\Async\Module\AsyncParallelModule;
use Ray\Di\AbstractModule;

class AppModule extends AbstractModule
{
    protected function configure(): void
    {
        $this->install(new PackageModule());
        $this->install(new AsyncParallelModule(
            namespace: 'MyVendor\MyApp',
            context: 'prod-app',
            appDir: dirname(__DIR__),
        ));
    }
}
```

Pool size defaults to CPU core count. To override:

```
$this->install(new AsyncParallelModule(
    namespace: 'MyVendor\MyApp',
    context: 'prod-app',
    appDir: dirname(__DIR__),
    poolSize: 8,
));
```

### Swoole Module (ext-swoole)

[](#swoole-module-ext-swoole)

For applications already running on Swoole HTTP Server with high concurrency requirements.

```
use BEAR\Async\Module\AsyncSwooleModule;
use BEAR\Async\Module\PdoPoolEnvModule;
use Ray\Di\AbstractModule;

class AppModule extends AbstractModule
{
    protected function configure(): void
    {
        $this->install(new PackageModule());
        $this->install(new AsyncSwooleModule());
        $this->install(new PdoPoolEnvModule(
            'PDO_DSN',
            'PDO_USER',
            'PDO_PASSWORD',
        )); // Connection pool required
    }
}
```

Which Module Should I Use?
--------------------------

[](#which-module-should-i-use)

Use CaseRecommended ModulePHP-FPM / Apache with embedded resources`AsyncParallelModule`Swoole HTTP Server`AsyncSwooleModule`### Comparison

[](#comparison)

AsyncParallelModuleAsyncSwooleModuleConcurrencyThread pool (CPU cores)Coroutines (thousands)PDO handlingIsolated per threadConnection pool requiredServerPHP-FPM / ApacheSwoole HTTP ServerSetupSimpleRequires Swoole serverHow It Works
------------

[](#how-it-works)

The AsyncLinker replaces the standard Linker to enable parallel execution of resource requests:

1. **Level-by-level execution**: Requests are processed level by level
2. **Request deduplication**: Same requests are merged and executed only once
3. **Result caching**: Results are cached to avoid redundant requests

```
Level 1: Users → all user requests execute in parallel
Level 2: Posts for each user → all post requests execute in parallel
Level 3: Comments for each post → all comment requests execute in parallel

```

Documentation
-------------

[](#documentation)

- [Parallel Execution Architecture and Performance Analysis](https://bearsunday.github.io/BEAR.Async/parallel-execution-architecture.html) - Deep dive into architecture, AWS instance recommendations, and cost savings projections

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

[](#requirements)

- PHP 8.2+
- ext-parallel (ZTS PHP required) or ext-swoole for async execution

Mysqli Batch Execution
----------------------

[](#mysqli-batch-execution)

Execute multiple SQL queries in parallel using mysqli's native async support.

### Installation

[](#installation-1)

```
use BEAR\Async\Module\MysqliBatchModule;

class AppModule extends AbstractModule
{
    protected function configure(): void
    {
        $this->install(new MysqliBatchModule(
            host: 'localhost',
            user: 'root',
            pass: 'password',
            database: 'mydb',
        ));
    }
}
```

Or with environment variables:

```
use BEAR\Async\Module\MysqliEnvModule;

$this->install(new MysqliEnvModule(
    'MYSQLI_HOST',
    'MYSQLI_USER',
    'MYSQLI_PASSWORD',
    'MYSQLI_DATABASE',
));
```

### Usage

[](#usage-1)

```
use BEAR\Async\SqlBatch;
use BEAR\Async\SqlBatchExecutorInterface;

class MyService
{
    public function __construct(
        private SqlBatchExecutorInterface $executor,
    ) {}

    public function getData(int $userId): array
    {
        // Execute multiple queries in parallel with invocable pattern
        $results = (new SqlBatch($this->executor, [
            'user' => ['SELECT * FROM users WHERE id = :id', ['id' => $userId]],
            'posts' => ['SELECT * FROM posts WHERE user_id = :user_id', ['user_id' => $userId]],
            'comments' => ['SELECT * FROM comments WHERE user_id = :user_id', ['user_id' => $userId]],
        ]))();

        return [
            'user' => $results['user'][0] ?? null,
            'posts' => $results['posts'],
            'comments' => $results['comments'],
        ];
    }
}
```

### Architecture

[](#architecture)

ClassDescription`SqlBatch`Invocable value object with `__invoke()` for one-line execution`SqlBatchExecutorInterface`Stateless executor interface (singleton-safe)`MysqliBatchExecutor`Async execution using `mysqli_poll``SyncBatchExecutor`Sequential execution for testing/fallback

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance80

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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

105d ago

Major Versions

0.1.0 → 1.x-dev2026-02-02

### Community

Maintainers

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

---

Top Contributors

[![koriym](https://avatars.githubusercontent.com/u/529021?v=4)](https://github.com/koriym "koriym (100 commits)")

---

Tags

asyncasyncswooleparallel

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bear-async/health.svg)

```
[![Health](https://phpackages.com/badges/bear-async/health.svg)](https://phpackages.com/packages/bear-async)
```

###  Alternatives

[jolicode/castor

A lightweight and modern task runner. Automate everything. In PHP.

53541.0k3](/packages/jolicode-castor)[aza/thread

AzaThread - Anizoptera CMF simple and powerful threads emulation component for PHP (based on forks).

7128.7k2](/packages/aza-thread)[amphp/cluster

Building multi-core network applications with PHP.

6224.8k1](/packages/amphp-cluster)[orisai/scheduler

Cron job scheduler - with locks, parallelism and more

4037.1k4](/packages/orisai-scheduler)[fghazaleh/multi-thread-manager

Multi-thread manager using Symfony process component

172.6k](/packages/fghazaleh-multi-thread-manager)

PHPackages © 2026

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