PHPackages                             denismitr/async-runner - 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. denismitr/async-runner

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

denismitr/async-runner
======================

Run PHP tasks asynchronously with the PCNTL extension

0.1(7y ago)4161MITPHPPHP ^7.1

Since May 18Pushed 7y ago1 watchersCompare

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

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

PHP Async Task Runner
=====================

[](#php-async-task-runner)

[![Build Status](https://camo.githubusercontent.com/31f00c05051e99f5d2c0172b4f36fed63e7f5481004b472fba8ddf926d270a27/68747470733a2f2f7472617669732d63692e6f72672f64656e69736d6974722f776169742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/denismitr/wait)

### Run PHP tasks asynchronously with the PCNTL extension

[](#run-php-tasks-asynchronously-with-the-pcntl-extension)

### Installation

[](#installation)

```
composer require denismitr/async-runner
```

### Usage

[](#usage)

```
$wg = WaitGroup::create();
$counter = 0;

foreach (range(1, 10) as $i) {
    $wg->add(function () {
        usleep(200); // some action here that takes time
        return 5;
    })->then(function (int $result) use (&$counter) {
        $counter += $result;
    });
}

$wg->wait();

$counter; // 50
```

Example with AsyncTask inheritance

```
// Create a class(es) that inherit from AsyncTask
use Denismitr\Async\AsyncTask;

class TestAsyncTask1 extends AsyncTask
{
    public function __construct($passSomething)
    {
        // Some initialization here
    }

    public function run()
    {
        usleep(1000); // some action here

        return 'some result';
    }
}

// Run

$wg = WaitGroup::create();

$wg->add(new TestAsyncTask1($passSomething));
$wg->add(new TestAsyncTask2($passSomething));

$results = $wg->wait();

foreach($results as $result) {
    // gives 2 results of 2 async tasks
}
```

You can check the result of each task by id, to help preserve the order

```
$wg = WaitGroup::create();

$idA = $wg->add(new TestAsyncTask('foo'))->getId();
$idB = $wg->add(new TestAsyncTask('bar'))->getId();
$idC = $wg->add(new TestAsyncTask('baz'))->getId();

$results = $wg->wait();

$this->assertEquals('foo', $results[$idA]);
$this->assertEquals('bar', $results[$idB]);
$this->assertEquals('baz', $results[$idC]);
```

You can set max concurrent processes limit

```
$wg = WaitGroup::create()->setMaxConcurrently(2);

$startTime = microtime(true);

foreach (range(1, 3) as $i) {
    $wg->add(function () {
        sleep(1);
    });
}

$wg->wait(); // Will run only 2 tasks in parallell, then the 3rd one
```

You can set a timeout

```
$wg = WaitGroup::create()->setTimeout(3);

$timedOut = 0;

foreach (range(1, 5) as $i) {
    $wg->add(function () use ($i) {
        sleep($i);
    })->timeout(function () use (&$timedOut) {
        $timedOut += 1;
    });
}

$wg->wait();

$this->assertEquals(3, $timedOut);
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity49

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

2918d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6d68ae5d5ca94f49a69f961a7825865d92247b09e276a25fcc6ad485d4c8c964?d=identicon)[denismitr](/maintainers/denismitr)

---

Top Contributors

[![denismitr](https://avatars.githubusercontent.com/u/16356446?v=4)](https://github.com/denismitr "denismitr (29 commits)")

---

Tags

asyncpcntlphpasyncconcurrencyTasksrunnerpcntldenismitr

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[amphp/amp

A non-blocking concurrency framework for PHP applications.

4.4k123.4M323](/packages/amphp-amp)[revolt/event-loop

Rock-solid event loop for concurrent PHP applications.

91943.6M138](/packages/revolt-event-loop)[jolicode/castor

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

53541.0k3](/packages/jolicode-castor)[clue/mq-react

Mini Queue, the lightweight in-memory message queue to concurrently do many (but not too many) things at once, built on top of ReactPHP

144691.7k4](/packages/clue-mq-react)[orisai/scheduler

Cron job scheduler - with locks, parallelism and more

4037.1k4](/packages/orisai-scheduler)[clue/reactphp-flux

Flux, the lightweight stream processor to concurrently do many (but not too many) things at once, built on top of ReactPHP.

59118.6k1](/packages/clue-reactphp-flux)

PHPackages © 2026

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