PHPackages                             kesha-dev/yii2-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. kesha-dev/yii2-async

ActiveYii2-extension[Queues &amp; Workers](/categories/queues)

kesha-dev/yii2-async
====================

Provide an easy way to run code asynchronously for Yii2 application

v1.0.1(2y ago)043BSD-3-ClausePHPPHP &gt;7.1

Since Sep 4Pushed 2y agoCompare

[ Source](https://github.com/kesha-dev/yii2-async)[ Packagist](https://packagist.org/packages/kesha-dev/yii2-async)[ RSS](/packages/kesha-dev-yii2-async/feed)WikiDiscussions master Synced 1mo ago

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

Yii2 Async
==========

[](#yii2-async)

[![Latest Stable Version](https://camo.githubusercontent.com/705afa81b7b704fde4c3e9b99c4586728d370db9ce5b99955536a1f97f176698/68747470733a2f2f706f7365722e707567782e6f72672f76786d2f796969322d6173796e632f762f737461626c65)](https://packagist.org/packages/vxm/yii2-async)[![Total Downloads](https://camo.githubusercontent.com/b96177f33af08a6522857f3aaadff7aba485b99ea90a67badf9ad99e36e57218/68747470733a2f2f706f7365722e707567782e6f72672f76786d2f796969322d6173796e632f646f776e6c6f616473)](https://packagist.org/packages/vxm/yii2-async)[![Build Status](https://camo.githubusercontent.com/1502a9d861cefaf129576529497f689cc9bfcd7e7d828c72121fc7f6285b0151/68747470733a2f2f7472617669732d63692e6f72672f76756f6e6778756f6e676d696e682f796969322d6173796e632e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/vuongxuongminh/yii2-async)[![Code Coverage](https://camo.githubusercontent.com/1c93bf3161710c4c05d82227e01de2b0cc5aa6965a06d2bb364c6f9ff23552de/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f76756f6e6778756f6e676d696e682f796969322d6173796e632f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/vuongxuongminh/yii2-async/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/74761d72dd2aa6fe5941bf89cc36463be56f74921ebbbb7bfb94ec493010784b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f76756f6e6778756f6e676d696e682f796969322d6173796e632f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/vuongxuongminh/yii2-async/?branch=master)[![Yii2](https://camo.githubusercontent.com/d6b0929173e28cc627430d2519ca1853466a70f37395877eaf4820cb3e1e1909/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f506f77657265645f62792d5969695f4672616d65776f726b2d677265656e2e7376673f7374796c653d666c6174)](http://www.yiiframework.com/)

About it
--------

[](#about-it)

An extension provide an easy way to run code asynchronous and parallel base on [spatie/async](https://github.com/spatie/async) wrapper for Yii2 application.

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

[](#requirements)

- [PHP &gt;= 7.1](http://php.net)
- [yiisoft/yii2 &gt;= 2.0.13](https://github.com/yiisoft/yii2)

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

[](#installation)

Require Yii2 Async using [Composer](https://getcomposer.org):

```
composer require vxm/yii2-async
```

Usage
-----

[](#usage)

### Configure

[](#configure)

Add the component to your application configure file:

```
[
    'components' => [
        'async' => [
            'class' => 'vxm\async\Async',
            'appConfigFile' => '@app/config/async.php' // optional when you need to use yii feature in async process.
        ]
    ]
]
```

Because async code run in difference process you need to setup yii environment to use components via property `appConfigFile`. Example of an async app config file:

```
define('YII_ENV', 'dev');
define('YII_DEBUG', true);

return [
    'id' => 'async-app',
    'basePath' => __DIR__,
    'runtimePath' => __DIR__ . '/runtime',
    'aliases' => [
        '@frontend' => dirname(__DIR__, 2) . '/frontend',
        '@backend' => dirname(__DIR__, 2) . '/backend'
    ]
];
```

Make sure all of your aliases define in it to support an autoload.

### Run async code

[](#run-async-code)

After add it to application components, now you can run an async code:

```
Yii::$app->async->run(function() {
     // do a thing.
});
```

### Async events

[](#async-events)

When creating asynchronous processes, you can add the following event hooks on a process in the second parameter.

```
Yii::$app->async->run(function() {

    if (rand(1, 2) === 1) {

        throw new \YourException;
    }

    return 123;
}, [
    'success' => function ($result) {

        echo $result; // 123

    },
    'catch' => function (\YourException $exception) {

        // catch only \YourException

    },
    'error' => function() {

        // catch all exceptions

    },
    'timeout' => function() {

        // call when task timeout default's 15s

    }
]);
```

### Wait process

[](#wait-process)

Sometime you need to wait a code executed, just call `wait()` after `run()`:

```
Yii::$app->async->run(function() {
    // do a thing.
})->wait();
```

Or you can wait multi tasks executed:

```
Yii::$app->async->run([YourAsyncClass::class, 'handleA']);
Yii::$app->async->run([YourAsyncClass::class, 'handleD']);
Yii::$app->async->run([YourAsyncClass::class, 'handleC']);
Yii::$app->async->run([YourAsyncClass::class, 'handleD']);

$results = Yii::$app->async->wait(); // results return from tasks above.
```

### Working with task

[](#working-with-task)

Besides using closures, you can also work with a Task. A Task is useful in situations where you need more setup work in the child process.

The Task class makes this easier to do.

```
use vxm\async\Task;

class MyTask extends Task
{

    public $productId;

    public function run()
    {
        // Do the real work here.

    }
}

// Do task async use like an anonymous above.

Yii::$app->async->run(new MyTask([
    'productId' => 123

]));
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 86.8% 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 ~1 days

Total

2

Last Release

977d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ff30ed293e81db317c0bd547fffc36974956c9719ca057f484bacd788236724d?d=identicon)[kesha](/maintainers/kesha)

---

Top Contributors

[![vuongxuongminh](https://avatars.githubusercontent.com/u/38932626?v=4)](https://github.com/vuongxuongminh "vuongxuongminh (33 commits)")[![bengower](https://avatars.githubusercontent.com/u/5861738?v=4)](https://github.com/bengower "bengower (5 commits)")

---

Tags

asyncyii2extensionphp-asyncyii2-async

### Embed Badge

![Health badge](/badges/kesha-dev-yii2-async/health.svg)

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

###  Alternatives

[vxm/yii2-async

Provide an easy way to run code asynchronously for Yii2 application

2334.2k](/packages/vxm-yii2-async)[trntv/yii2-command-bus

Yii2 Command Bus extension

57625.1k8](/packages/trntv-yii2-command-bus)[mikemadisonweb/yii2-rabbitmq

Wrapper based on php-amqplib to incorporate messaging in your Yii2 application via RabbitMQ. Inspired by RabbitMqBundle for Symfony 2, really awesome package.

74262.1k1](/packages/mikemadisonweb-yii2-rabbitmq)[bubasuma/yii2-simplechat

A simple chat for your yii2 application

889.5k](/packages/bubasuma-yii2-simplechat)[ignatenkovnikita/yii2-queuemanager

Yii2 Queue Manager

2061.8k2](/packages/ignatenkovnikita-yii2-queuemanager)

PHPackages © 2026

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