PHPackages                             taguz91/yii2-async-await - 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. taguz91/yii2-async-await

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

taguz91/yii2-async-await
========================

About Async await for php yii2 integration, this uses amphp

1.1.1(4y ago)02.0k↓50%1Apache-2.0PHP

Since Apr 15Pushed 4y ago1 watchersCompare

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

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

Async await
===========

[](#async-await)

Async await for php yii2 integration, this uses amphp and support callbacks and Task

[![Latest Stable Version](https://camo.githubusercontent.com/09d6d6b3145dddf3bf5bbac5755023c8c7d960a7b67124450a17e20d58d9ab26/68747470733a2f2f706f7365722e707567782e6f72672f746167757a39312f796969322d6173796e632d61776169742f76)](//packagist.org/packages/taguz91/yii2-async-await)[![Total Downloads](https://camo.githubusercontent.com/665918a7cd12601973a6d440c10ad30ef96a1e1a8c85bc5dbfdbf3b9021d1a31/68747470733a2f2f706f7365722e707567782e6f72672f746167757a39312f796969322d6173796e632d61776169742f646f776e6c6f616473)](//packagist.org/packages/taguz91/yii2-async-await)[![Latest Unstable Version](https://camo.githubusercontent.com/e6b4bca0cac2c82ef41bff80d4c8972c736feaa576ad0b1c13ada4a76d07f650/68747470733a2f2f706f7365722e707567782e6f72672f746167757a39312f796969322d6173796e632d61776169742f762f756e737461626c65)](//packagist.org/packages/taguz91/yii2-async-await)[![License](https://camo.githubusercontent.com/2c8ce377719dec29daaa515b8aaa36ca368f8de137f529918d84c0c3659142d8/68747470733a2f2f706f7365722e707567782e6f72672f746167757a39312f796969322d6173796e632d61776169742f6c6963656e7365)](//packagist.org/packages/taguz91/yii2-async-await)

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
composer require --prefer-dist taguz91/yii2-async-await

```

or add

```
"taguz91/yii2-async-await": "~1.0.0"

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

Once the extension is installed, simply use it in your code by:

Need to configure the bootstrap configuration app, because the async run in another context.

The following examples was tested in advanced template.

For example:

```
return [
    'id' => 'app-async',
    'basePath' => dirname(__DIR__),
    // Your controllers, you can change this to backend\controllers
    'controllerNamespace' => 'frontend\controllers',
    'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
    'aliases' => [
        '@bower' => '@vendor/bower-asset',
        '@npm'   => '@vendor/npm-asset',
    ],
    // Required components for async functions
    'components' => [
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        // Config your database
        'db' => [
            'class' => 'yii\db\Connection',
            'dsn' => 'mysql:host=localhost;dbname=yii2advanced',
            'username' => 'root',
            'password' => '',
            'charset' => 'utf8',
        ],
    ],
    'params' => [],
];
```

Also need to create the entry script, for autoload the dependecies and start Yii2 app.

For example:

```
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
// Autoload for composer an yii2
require __DIR__ . '/../../vendor/autoload.php';
require __DIR__ . '/../../vendor/yiisoft/yii2/Yii.php';
require __DIR__ . '/../../common/config/bootstrap.php';

// Your custom configuration for async
$config = require __DIR__ . '/async-main.php';
// You can change the console application to web application
// You dont have acces to vars or configuration in parent context
new yii\console\Application($config);
```

Adding to web app, in components section you need to add this configuration:

```
[
    ...,
    'components' => [
        // If you want to use callbacks
        'asyncAwait' => [
            'class' => \taguz91\AsyncAwait\AsyncAwait::class,
            // Your own entry script, see the above examples
            'loader' => __DIR__ . '/async.php'
        ],
        // If you want to use classes, this is more faster
        'asyncTask' => [
            'class' => \taguz91\AsyncAwait\AsyncTask::class,
            // Your own entry script, see the above examples
            'loader' => __DIR__ . '/async.php'
        ],
    ]
]
```

Code example for callbacks usage:

```
use common\models\User;

// Adding you async function
Yii::$app->asyncAwait->add('sendUserEmail', function (string $idUser, string $sender) {
    $user = User::findOne($idUser);
    // Return any serializable data, is prefer return a basic array response
    return \common\models\Email::sendUser($user, $sender);
}, $idUser, $sender);

Yii::$app->asyncAwait->add('sendUserMessage', function (string $message, string $number) {
    if ($number === '') return 'Number is required.';
    return \common\models\Phone::sendMessage($message, $number);
}, $message, $number);

// Execute your asynct functions
$responses = Yii::$app->asyncAwait->run();
// Getting especific response
$emailResponse = $responses['sendUserEmail'];
```

Code example for Tasks:

```
// This class is autoloadable
namespace common\tasks;

use Amp\Parallel\Worker\Environment;
use Amp\Parallel\Worker\Task;
use yii\helpers\VarDumper;

class PrintTask implements Task
{
    private $text;

    public function __construct(string $text)
    {
        $this->text = $text;
    }

    /**
     * {@inheritdoc}
     */
    public function run(Environment $environment)
    {
        return [
            'response' => "FUTURE PROMISE WORKER {$this->text}",
            'enviroment' => VarDumper::dumpAsString($environment),
        ];
    }
}

/** @var \taguz91\AsyncAwait\AsyncTask */
$async = Yii::$app->asyncTask;

$async->add('1', new PrintTask('THIS IS MY LARGE TEXT'));
$response = $async->run();
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity54

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 ~167 days

Total

3

Last Release

1521d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7869f5317dfdc136244ad47b455c6840e2f929271769a46e8cc0ac5dbd7999df?d=identicon)[taguz91](/maintainers/taguz91)

---

Top Contributors

[![taguz91](https://avatars.githubusercontent.com/u/42211711?v=4)](https://github.com/taguz91 "taguz91 (7 commits)")

---

Tags

asyncyii2extensionawait

### Embed Badge

![Health badge](/badges/taguz91-yii2-async-await/health.svg)

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

###  Alternatives

[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)[vxm/yii2-async

Provide an easy way to run code asynchronously for Yii2 application

2334.2k](/packages/vxm-yii2-async)[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)
