PHPackages                             agussuroyo/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. agussuroyo/async

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

agussuroyo/async
================

A simple asynchronous process manager for PHP using pcntl.

1.0.0(1y ago)02MITPHPPHP &gt;=7.4CI passing

Since Mar 19Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/agussuroyo/async)[ Packagist](https://packagist.org/packages/agussuroyo/async)[ RSS](/packages/agussuroyo-async/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

agussuroyo/async
================

[](#agussuroyoasync)

[![CI](https://github.com/agussuroyo/async/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/agussuroyo/async/actions/workflows/ci.yml/badge.svg?branch=master)

Run PHP work in parallel by forking child processes. Each task returns a `Future` that resolves to the callback's return value — or rethrows its exception in the parent.

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

[](#requirements)

- PHP 7.4 – 8.4
- `pcntl` extension

`pcntl` is unavailable on native Windows and disabled in most non-CLI SAPIs (php-fpm, mod\_php). This library is for CLI scripts and long-running daemons.

Install
-------

[](#install)

```
composer require agussuroyo/async
```

Quick start
-----------

[](#quick-start)

```
use AgusSuroyo\Async\Async;

$async = new Async();

$future = $async->run(function () {
    return fetchPrice('SKU-1');
});

$price = $future->await(); // blocks until the child finishes
```

Concurrent fan-out
------------------

[](#concurrent-fan-out)

```
$async = new Async();

$futures = [];
foreach ($skus as $sku) {
    $futures[$sku] = $async->run(function () use ($sku) {
        return fetchPrice($sku);
    });
}

$prices = array_map(function ($f) { return $f->await(); }, $futures);
```

Children run in parallel up to the concurrency limit. Their `await()` order doesn't matter — each future resolves whenever its child finishes.

Errors propagate
----------------

[](#errors-propagate)

```
$future = $async->run(function () {
    throw new \RuntimeException('boom');
});

try {
    $future->await();
} catch (\RuntimeException $e) {
    // 'boom' — child file/line/trace are appended to the message
}
```

If the original exception class's constructor isn't `(string $message, int $code)`-compatible, the parent rethrows as `RuntimeException` with the original class name embedded in the message. The child stack trace is preserved either way.

Concurrency limit
-----------------

[](#concurrency-limit)

Default is `CPU cores × 2`. Override at construction or at runtime:

```
$async = new Async(4);  // at most 4 children at once
$async->max(8);         // change later
```

When the limit is reached, `run()` blocks until a slot frees up.

Fire-and-wait
-------------

[](#fire-and-wait)

If you don't need individual return values, ignore the futures and call `wait()`:

```
foreach ($items as $item) {
    $async->run(function () use ($item) {
        process($item);
    });
}
$async->wait(); // blocks until every scheduled child has finished
```

Caveats
-------

[](#caveats)

- **Return values must be `serialize()`-safe.** They cross the fork via a Unix socket pipe. Resources (PDO connections, sockets, file handles) can't ride the channel — return scalars, arrays, or value objects.
- **No shared state across children.** Each fork gets a copy-on-write snapshot of the parent's memory; mutations in the child stay in the child.
- **No event-loop integration.** This is a cooperative scheduler that pumps inside `wait()` and `Future::await()`. Use a dedicated event loop (Revolt/Amp/ReactPHP) if you need async I/O.

Testing
-------

[](#testing)

```
docker compose up -d
docker compose exec php composer test
docker compose exec php composer analyse
```

License
-------

[](#license)

MIT.

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance68

Regular maintenance activity

Popularity2

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 64.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

Unknown

Total

1

Last Release

472d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5734710?v=4)[Agus Suroyo](/maintainers/agussuroyo)[@agussuroyo](https://github.com/agussuroyo)

---

Top Contributors

[![agussuroyo](https://avatars.githubusercontent.com/u/5734710?v=4)](https://github.com/agussuroyo "agussuroyo (18 commits)")[![claude](https://avatars.githubusercontent.com/u/81847?v=4)](https://github.com/claude "claude (10 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[processmaker/nayra

BPMN compliant engine

139107.9k2](/packages/processmaker-nayra)[juststeveking/uri-builder

A simple URI builder in PHP that is slightly opinionated

20298.4k6](/packages/juststeveking-uri-builder)[undefinedoffset/silverstripe-keyboardshortcuts

Adds keyboard shortcuts for common tasks to SilverStripe 4.0+ (ctrl/command+s for save anyone?)

1811.9k](/packages/undefinedoffset-silverstripe-keyboardshortcuts)

PHPackages © 2026

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