PHPackages                             kage3f/rux-concorrency - 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. kage3f/rux-concorrency

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

kage3f/rux-concorrency
======================

A lightweight, native PHP concorrency library using Fibers

v1.4.2(6mo ago)117MITPHPPHP &gt;=8.1

Since Dec 20Pushed 6mo agoCompare

[ Source](https://github.com/kage3f/rux-concurrency)[ Packagist](https://packagist.org/packages/kage3f/rux-concorrency)[ Docs](https://github.com/kage3f/fiber-async)[ RSS](/packages/kage3f-rux-concorrency/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (19)Used By (0)

 [![Rux Logo](assets/logo.svg)](assets/logo.svg)

Rux Concurrency
===============

[](#rux-concurrency)

[![Latest Stable Version](https://camo.githubusercontent.com/2b84c00f5c0cfce023faf04428905bb33d70ebed15f621b9e217d7cde15d9023/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b61676533662f7275782d636f6e636f7272656e63792e737667)](https://packagist.org/packages/kage3f/rux-concorrency)[![License](https://camo.githubusercontent.com/b26d6d61e2ffae240bc1f1605e09cfc1ed5313b5872ca31b18d93cb648aa91aa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6b61676533662f7275782d636f6e636f7272656e63792e737667)](https://packagist.org/packages/kage3f/rux-concorrency)

A lightweight, zero-dependency native PHP concurrency library built on top of **Fibers** (PHP 8.1+). It provides a simple `async/await` implementation for cooperative multitasking.

Features
--------

[](#features)

- 🚀 **Cooperative Multitasking**: Run multiple I/O-bound tasks concurrently.
- 🛠 **Simple API**: Familiar `async`, `await`, and `wait` functions.
- 📦 **Zero Dependencies**: Pure PHP, no extensions like `parallel` or `swoole` required.
- 🔌 **Event Loop**: Built-in scheduler with support for Timers and non-blocking I/O (Streams).
- 🌐 **Robust HTTP Client**: High-level `get()` and `get_json()` with built-in support for:
    - **SSL/TLS**: Secure connections out of the box.
    - **Redirects**: Automatically follows 301, 302, 307, and 308 redirects.
    - **Compression**: Automatic GZIP decompression.
    - **Chunked Encoding**: Handles chunked transfer encoding seamlessly.
    - **Validation**: Throws detailed exceptions for non-2xx status codes or JSON failures.

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

[](#installation)

Install the package via Composer:

```
composer require kage3f/rux-concorrency
```

API Documentation
-----------------

[](#api-documentation)

This library exposes several helper functions in the `Rux` namespace.

### `Rux\async(callable $callback): Task`

[](#ruxasynccallable-callback-task)

Starts a new asynchronous task.

- **What it does**: Creates a new `Task` instance, adds it to the Scheduler, and starts its execution immediately until it hits a suspension point.
- **Returns**: A `Task` instance.

### `Rux\await(Task $task): mixed`

[](#ruxawaittask-task-mixed)

Waits for a task to complete.

- **What it does**: Suspends the current fiber until the provided task is finished.
- **Returns**: The task's return value. Rethrows any exception occurred inside the task.

### `Rux\wait(): void`

[](#ruxwait-void)

Runs the task scheduler.

- **What it does**: Starts the main loop that processes all tasks. This function is blocking and returns when all tasks are done.

### `Rux\sleep(int $milliseconds): void`

[](#ruxsleepint-milliseconds-void)

Pauses execution without blocking the process.

- **What it does**: Suspends the current fiber for a set period, allowing other tasks to run.

### `Rux\get(string $url): string`

[](#ruxgetstring-url-string)

Performs a non-blocking GET request.

- **Features**: Handles SSL, redirects, GZIP, and chunked encoding.
- **Throws**: `Exception` on connection failure or non-2xx status codes.

### `Rux\get_json(string $url): array`

[](#ruxget_jsonstring-url-array)

Performs a GET request and decodes the JSON response.

- **Throws**: `Exception` if the response is not a valid JSON or the request fails.

### `Rux\parallel_each(array $items, callable $callback, int $concurrency = 10): void`

[](#ruxparallel_eacharray-items-callable-callback-int-concurrency--10-void)

Processes an array in parallel.

- **What it does**: Splits the array into chunks and runs each chunk in a separate asynchronous task. Useful for bulk database inserts or processing large datasets.

### `Rux\parallel_map(array $items, callable $callback, int $concurrency = 10): array`

[](#ruxparallel_maparray-items-callable-callback-int-concurrency--10-array)

Maps an array in parallel and returns the results.

- **What it does**: Similar to `parallel_each`, but collects and returns the results from all tasks.

---

Usage Examples
--------------

[](#usage-examples)

### Basic Concurrency

[](#basic-concurrency)

```
use function Rux\async;
use function Rux\sleep;
use function Rux\wait;

async(function() {
    echo "Task 1: Starting...\n";
    sleep(1000); // Non-blocking sleep
    echo "Task 1: Finished!\n";
});

async(function() {
    echo "Task 2: Starting...\n";
    sleep(500);
    echo "Task 2: Finished!\n";
});

wait(); // Execute the scheduler
```

### Parallel Processing (Database/Bulk)

[](#parallel-processing-databasebulk)

```
use function Rux\async;
use function Rux\parallel_each;
use function Rux\wait;

async(function() use ($largeDataset) {
    // Processes the dataset using 10 concurrent workers
    parallel_each($largeDataset, function($chunk) {
        $db = getDbConnection();
        foreach ($chunk as $item) {
            $db->prepare("INSERT INTO table ...")->execute($item);
            \Rux\sleep(0); // Optional: yield to other tasks
        }
    }, concurrency: 10);
});

wait();
```

### Async/Await Pattern

[](#asyncawait-pattern)

```
use function Rux\async;
use function Rux\await;
use function Rux\wait;

async(function() {
    $task1 = async(fn() => "Data from API 1");
    $task2 = async(fn() => "Data from API 2");

    // Suspends this fiber until the tasks are finished
    $res1 = await($task1);
    $res2 = await($task2);

    echo "$res1, $res2\n";
});

wait();
```

### High-Level HTTP Requests

[](#high-level-http-requests)

You don't need to deal with streams manually. The library provides simple helpers:

```
use function Rux\async;
use function Rux\get_json;
use function Rux\wait;

async(function() {
    try {
        $data = get_json('https://api.example.com/data');
        print_r($data);
    } catch (\Exception $e) {
        echo "Error: " . $e->getMessage();
    }
});

wait();
```

Real-World Examples
-------------------

[](#real-world-examples)

Check the `examples/` directory for professional use cases:

1. **[Dashboard Aggregator](examples/dashboard_aggregator.php)**: Simulates fetching data from multiple microservices concurrently.
2. **[Concurrent HTTP](examples/http_example.php)**: Demonstrates fetching multiple external URLs using the high-level `get()` function.

How it works
------------

[](#how-it-works)

`RuxConcorrency` uses PHP **Fibers** to pause and resume execution. When a task performs a non-blocking operation (like `Rux\sleep` or a non-blocking stream read), it suspends itself, allowing the `Scheduler` to run other pending tasks.

License
-------

[](#license)

MIT License. Please see the [LICENSE](LICENSE) file for more information.

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance67

Regular maintenance activity

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

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

Every ~0 days

Total

18

Last Release

194d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/58daccd41fc68387a1d1b31664e8d4b7d3f119398eea69250086c904b3af447b?d=identicon)[kage3f](/maintainers/kage3f)

---

Top Contributors

[![tiago-rodrigues-dev](https://avatars.githubusercontent.com/u/61149680?v=4)](https://github.com/tiago-rodrigues-dev "tiago-rodrigues-dev (28 commits)")

---

Tags

phpasyncschedulerFibersawaitconcorrency

### Embed Badge

![Health badge](/badges/kage3f-rux-concorrency/health.svg)

```
[![Health](https://phpackages.com/badges/kage3f-rux-concorrency/health.svg)](https://phpackages.com/packages/kage3f-rux-concorrency)
```

###  Alternatives

[revolt/event-loop

Rock-solid event loop for concurrent PHP applications.

92553.8M227](/packages/revolt-event-loop)[orisai/scheduler

Cron job scheduler - with locks, parallelism and more

4044.1k5](/packages/orisai-scheduler)[jenner/async-mysql-php

php mysql async client

401.0k](/packages/jenner-async-mysql-php)

PHPackages © 2026

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