PHPackages                             happyslucker/a-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. [HTTP &amp; Networking](/categories/http)
4. /
5. happyslucker/a-async

ActiveLibrary[HTTP &amp; Networking](/categories/http)

happyslucker/a-async
====================

High-performance parallel processing &amp; async library for PHP.

1.0.0(7mo ago)42MITPHPPHP ^8.3

Since Nov 28Pushed 1mo agoCompare

[ Source](https://github.com/HappySlucker/a-async)[ Packagist](https://packagist.org/packages/happyslucker/a-async)[ RSS](/packages/happyslucker-a-async/feed)WikiDiscussions main Synced today

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

[![AAsync](logo.png)](logo.png)

[![PHP Version](https://camo.githubusercontent.com/4be5bc47f836da8c75538d91cc7ceb22c384d6073ff76a3138d602fe965e5a21/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e332d3737376262342e7376673f7374796c653d666c61742d737175617265)](https://www.php.net/)[![License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Type](https://camo.githubusercontent.com/142064098c8e54c767ae6306e82698cd1c004746bcc13286aa9221f0c90d67c2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f747970652d6c6962726172792d626c75652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/happyslucker/a-async)

About AAsync
============

[](#about-aasync)

---

**AAsync \[Almost Async\]** is a high-performance, lightweight PHP library designed for parallel processing and asynchronous execution. By leveraging **PCNTL forking** for CPU-bound tasks and **PHP Fibers** for I/O-bound operations, AAsync allows you to break the synchronous barrier of PHP with a clean, modern API.

✨ Features
----------

[](#-features)

---

- **Parallel CPU Processing:** Execute heavy computations in separate processes using `pcntl_fork`.
- **Fiber-based Async I/O:** Non-blocking HTTP requests using Fibers and `curl_multi`.
- **Process Pooling:** Managed worker pools with a configurable concurrency limit.
- **Future-based Flow:** Implementation of `Future` objects with support for asynchronous chaining via `then()`, exception handling with `catch()`, and result resolution using `await()`.
- **High-Performance IPC:** Uses `stream_socket_pair` for parent-child communication with a custom binary protocol (Header + Payload) to ensure data integrity.
- **Simple Facade:** Unified entry point via `Async::cpu()` and `Async::http()`.

📦 Installation
--------------

[](#-installation)

---

Ensure you have `ext-pcntl`, `ext-posix`, and `ext-curl` installed.

```
composer require happyslucker/a-async
```

🚀 Quick Start
-------------

[](#-quick-start)

---

### 1. CPU-Bound Parallelism

[](#1-cpu-bound-parallelism)

Run heavy tasks in the background without blocking the main process. PHP

```
use HappySlucker\AAsync\Async;

// Run a heavy task in a separate process
$future = Async::cpu()->run(function(int $times): int {
    $result = 0;
    for ($i = 0; $i < $times; $i++) { $result += $i; }
    return $result;
}, 1000000);

// Do something else here...

// Get the result (blocks until finished)
echo "Result: " . $future->await();
```

### 2. Concurrent Map (Parallel Processing)

[](#2-concurrent-map-parallel-processing)

Process a collection of items in parallel with a concurrency limit.

```
use HappySlucker\AAsync\Async;

$items = [1, 2, 3, 4, 5];

$results = Async::cpu()->parallel(
    static fn(int $item): int => $item * 10,
    $items,
    concurrency: 3
);

print_r($results);
```

### 3. Asynchronous HTTP (Fibers)

[](#3-asynchronous-http-fibers)

Perform non-blocking HTTP requests. The execution yields back to the manager while waiting for the network.

```
use HappySlucker\AAsync\Async;

$http = Async::http();

// Start multiple requests
$f1 = $http->get('https://httpbin.org/get');
$f2 = $http->get('https://httpbin.org/delay/1');

// Await them - the FiberManager handles the concurrent execution automatically
$res1 = $f1->await();
$res2 = $f2->await();

echo $res1->statusCode;
```

🛠️ Advanced Architecture
------------------------

[](#️-advanced-architecture)

---

### The Future Pattern

[](#the-future-pattern)

Both CPU and HTTP tasks return a Future object. You can handle results via blocking await() or non-blocking then().

```
use HappySlucker\AAsync\Async;

function foo(): int
{
    return 5 + 5;
}

$future = Async::cpu()
    ->run(static fn(): int => foo())
    ->then(static fn(int $result): int => $result * 5);

print_r($future->await());
```

### Process Pool &amp; Reaping

[](#process-pool--reaping)

The ***ProcessPool*** automatically manages the lifecycle of child processes. It limits the number of active workers and "reaps" (cleans up) finished processes to prevent zombies and memory leaks.

### Communication Channel

[](#communication-channel)

AAsync uses a binary header protocol over Unix Sockets for parent-child communication:

- ***Serialization:*** Uses MsgPack (if available) for speed, falling back to JSON.
- ***Transport:*** stream\_socket\_pair provides a bi-directional pipe.

⚙️ Requirements
---------------

[](#️-requirements)

---

- ***PHP:*** 8.3 or higher
- ***Extensions:***
    - pcntl: Required for process forking.
    - posix: Required for process management.
    - curl: Required for async HTTP.
    - OS: Linux or macOS (Windows is not supported due to pcntl).

📜 License
---------

[](#-license)

---

The MIT License (MIT).

### Created by HappySlucker. Happy coding! 🍻

[](#created-by-happyslucker-happy-coding-)

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance80

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

217d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/248821202?v=4)[Pavel Bobrik](/maintainers/HappySlucker)[@HappySlucker](https://github.com/HappySlucker)

---

Top Contributors

[![HappySlucker](https://avatars.githubusercontent.com/u/248821202?v=4)](https://github.com/HappySlucker "HappySlucker (1 commits)")

---

Tags

httpasyncpromisesocketsconcurrentperformanceprocessparallelmultiprocessingpoolworkerFiberspcntl

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[hhxsv5/laravel-s

🚀 LaravelS is an out-of-the-box adapter between Laravel/Lumen and Swoole.

3.9k691.5k13](/packages/hhxsv5-laravel-s)[amphp/http-client

An advanced async HTTP client library for PHP, enabling efficient, non-blocking, and concurrent requests and responses.

7309.5M202](/packages/amphp-http-client)[kevinrob/guzzle-cache-middleware

A HTTP/1.1 Cache for Guzzle 6. It's a simple Middleware to be added in the HandlerStack. (RFC 7234)

44018.6M133](/packages/kevinrob-guzzle-cache-middleware)[khr/php-mcurl-client

wrap curl client (http client) for PHP 5.3; using php multi curl, parallel request and write asynchronous code

71230.4k6](/packages/khr-php-mcurl-client)[meabed/php-parallel-soap

Parallel, multi-curl PHP SoapClient that performs many SOAP requests concurrently

4393.5k](/packages/meabed-php-parallel-soap)[meabed/asynchronous-soap

Parallel, multi-curl PHP SoapClient that performs many SOAP requests concurrently

4411.7k](/packages/meabed-asynchronous-soap)

PHPackages © 2026

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