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.3.0(1mo ago)1321[1 issues](https://github.com/bearsunday/BEAR.Async/issues)MITPHPPHP ^8.2CI passing

Since Jan 26Pushed 1mo agoCompare

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

READMEChangelog (3)Dependencies (14)Versions (8)Used By (0)

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

[](#bearasync)

Async/parallel resource execution library for BEAR.Sunday

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

[](#why-bearasync)

BEAR.Async preserves your resource code. You choose an async execution mode at the application boundary — no async/await, no Promise, no yield, no rewrites of existing `#[Embed]` graphs.

```
#[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
```

Demo and Benchmarks
-------------------

[](#demo-and-benchmarks)

A runnable demo application lives in [`demo/`](demo/). It builds separate Docker images for ext-parallel and ext-swoole, starts MySQL, seeds a dashboard resource graph with 8 independent SQL-backed GET embeds, and exposes Sync, ext-parallel, and Swoole entrypoints.

```
cd demo
docker compose up -d --wait parallel
docker compose exec parallel composer install
docker compose exec parallel composer app -- get 'app://self/dashboard?user_id=1'
docker compose exec parallel composer async -- get 'app://self/dashboard?user_id=1'
```

The demo also includes cold one-shot CLI benchmarks and steady-state HTTP benchmarks with `wrk`:

```
docker compose exec parallel composer parallel-benchmark
docker compose exec parallel composer steady-state-parallel
docker compose up -d --wait swoole
docker compose exec swoole composer swoole-benchmark
docker compose exec swoole composer steady-state-swoole
```

See the [demo guide](demo/README.md) for setup details and [benchmark results](docs/benchmark-results.md) for measured numbers and adapter selection guidance.

Execution Modes
---------------

[](#execution-modes)

### Parallel execution (ext-parallel)

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

Recommended for typical PHP-FPM / Apache web applications with embedded resources.

Add `bin/async.php` next to `bin/app.php`. It hands off to the library bootstrap, which overlays the ext-parallel runtime on the normal AppModule:

```
bin/async.php → vendor/bear/async/bootstrap.php → AppModule + runtime overlay

```

```
