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

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

libelulasoft/yii2-async-await
=============================

About Async await for php yii2 integration, this uses amphp

1.0.0(3y ago)06.2k↓37.5%Apache-2.0PHP

Since Nov 10Pushed 3y agoCompare

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

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

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

[](#async-await)

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

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

[](#installation)

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

Either run

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

```

or add

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

```

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

Migration
---------

[](#migration)

Si quieres migrar de la version original `taguz91/yii2-async-await` a la nueva version `libelulasoft/yii2-async-await` debes seguir los siguientes pasos:

1. Eliminar la version original

```
composer remove taguz91/yii2-async-await

```

2. Instalar la nueva version

```
composer require libelulasoft/yii2-async-await

```

3. Actualizar los namespace donde se este utilizando la libreria, en todo el proyecto debemos reemplazar `taguz91\AsyncAwait\` a `Libelulasoft\AsyncAwait\`
4. Probar que todo funcione de forma correcta.

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' => \Libelulasoft\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' => \Libelulasoft\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 \Libelulasoft\AsyncAwait\AsyncTask */
$async = Yii::$app->asyncTask;

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

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

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

1286d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9c40f27cca6de9f480abe8ebbcaae7dcd9f28b22e4e7172d4b06cac1763fb860?d=identicon)[LibelulasoftEcuador](/maintainers/LibelulasoftEcuador)

---

Top Contributors

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

---

Tags

asyncyii2extensionawait

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/libelulasoft-yii2-async-await/health.svg)](https://phpackages.com/packages/libelulasoft-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)
