PHPackages                             bazilio/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. [Caching](/categories/caching)
4. /
5. bazilio/yii2-async

ActiveYii2-extension[Caching](/categories/caching)

bazilio/yii2-async
==================

Provides translucent api for moving large tasks out of request context

0.2.0(10y ago)6248.8k↓19.2%182MITPHPPHP &gt;=5.4.0

Since Jul 9Pushed 6y ago9 watchersCompare

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

READMEChangelog (10)Dependencies (7)Versions (19)Used By (2)

yii2-async
==========

[](#yii2-async)

[![Build Status](https://camo.githubusercontent.com/90f86a65e328132535ae818a5a31126af45b864d45ba468864240712c6394bf2/68747470733a2f2f7472617669732d63692e6f72672f62617a696c696f39312f796969322d6173796e632e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/bazilio91/yii2-async)[![Latest Stable Version](https://camo.githubusercontent.com/cae4486fd879208b48e03631bb764a890e4c71beb020073d361810d2c1679b29/68747470733a2f2f706f7365722e707567782e6f72672f62617a696c696f2f796969322d6173796e632f762f737461626c65)](https://packagist.org/packages/bazilio/yii2-async)[![Total Downloads](https://camo.githubusercontent.com/655839f5be9a67212321ca0aac1c118f431b1db67628db2077332b44f0aa6e53/68747470733a2f2f706f7365722e707567782e6f72672f62617a696c696f2f796969322d6173796e632f646f776e6c6f616473)](https://packagist.org/packages/bazilio/yii2-async)[![Latest Unstable Version](https://camo.githubusercontent.com/d7bb572b116e0c31300450df5c6cfbb27e8560dcc97468150e4759b768ed85b3/68747470733a2f2f706f7365722e707567782e6f72672f62617a696c696f2f796969322d6173796e632f762f756e737461626c65)](https://packagist.org/packages/bazilio/yii2-async)[![License](https://camo.githubusercontent.com/76f4a356268e929487db96498afa5261583276965780adfe67e06fb22d61c1e3/68747470733a2f2f706f7365722e707567782e6f72672f62617a696c696f2f796969322d6173796e632f6c6963656e7365)](https://packagist.org/packages/bazilio/yii2-async)

Provides translucent api for moving large tasks out of request response

Install: `php composer.phar require bazilio/yii2-async:dev-master`

##### Requirments:

[](#requirments)

- php &gt;=5.4
- Transports:
    - `yii\db\Connection`
    - [php-amqp](https://github.com/pdezwart/php-amqp)
    - [yii2-redis](https://github.com/yiisoft/yii2-redis)

##### Using with AMQP:

[](#using-with-amqp)

`php composer.phar require pdezwart/php-amqp:dev-master`

main.php:

```
'components' => [
    'async' => [
        'class' => 'bazilio\async\AsyncComponent',
        'transportClass' => 'bazilio\async\transports\AsyncAmqpTransport',
        'transportConfig' => [
            'host' => 'localhost',
            'login' => 'guest',
            'password' => 'guest',
            'vhost' => 'yii',
            'exchangeName' => 'yii'
        ]
    ]
]
```

##### Using with Redis:

[](#using-with-redis)

`php composer.phar require yiisoft/yii2-redis:*`

main.php:

```
'components' => [
    'redis' => [
        'class' => 'yii\redis\Connection',
        'hostname' => 'localhost',
        'port' => 6379,
        'database' => 0,
        'dataTimeout' => -1, // important for daemon and blocking queries
    ],
    'async' => [
        'class' => 'bazilio\async\AsyncComponent',
        'transportClass' => 'bazilio\async\transports\AsyncRedisTransport',
        'transportConfig' => [
            'connection' => 'redis',
        ]
    ]
]
```

##### Using with MySQL (probably any sql, but tested only with mysql)

[](#using-with-mysql-probably-any-sql-but-tested-only-with-mysql)

main.php:

```
'components' => [
    'db' => [
        'class' => 'yii\db\Connection',
        'dsn' => 'mysql:host=localhost;dbname=yii2advenced',
        'username' => 'root',
        'password' => '',
        'charset' => 'utf8',
    ],
    'async' => [
        'class' => 'bazilio\async\AsyncComponent',
        'transportClass' => 'bazilio\async\transports\AsyncMysqlTransport',
        'transportConfig' => [
            'connection' => 'db',
        ]
    ]
]
```

Apply migrations:

```
./yii migrate/up --migrationPath=@vendor/bazilio/yii2-async/migrations
```

##### Usage:

[](#usage)

#### Create and send:

[](#create-and-send)

Test class example:

```
class DownloadTask extends AsyncTask
{
    public $url;
    public $file;
    public static $queueName = 'downloads';

    public function execute()
    {
        return file_put_contents($this->file, file_get_contents($this->url));
    }
}

// create task
$task = new DownloadTask(['url' => 'http://localhost/', 'file' => '/tmp/localhost.html']);
\Yii::$app->async->sendTask($task);
```

Or call external method:

```
$task = new AsyncExecuteTask([
    'class' => 'common\components\MyDownloaderComponent',
    'method' => 'download',
    'arguments' => ['url' => 'http://localhost/', 'file' => '/tmp/localhost.html']
]);

$task::$queueName = 'downloads';

if (YII_ENV !== 'prod') {
    $task->execute();
} else {
    Yii::$app->async->sendTask($task);
}
```

#### Execute:

[](#execute)

Bash way:

Fill console config:

```
'controllerMap' => [
        'async-worker' => [
            'class' => 'bazilio\async\commands\AsyncWorkerCommand',
        ],
    ],
```

Run:

```
# Process and exit on finish
./yii async-worker/execute downloads
# Process and wait for new tasks (only redis)
./yii async-worker/daemon downloads
```

Code way:

```
while ($task = \Yii::$app->async->receiveTask('downloads')) {
    if ($task->execute()) {
        \Yii::$app->async->acknowledgeTask($task);
    }
}
```

For more code examples look into tests:

- [BaseTestClass](tests/unit/BaseTestClass.php)

###### Runing tests:

[](#runing-tests)

```
vendor/bin/codecept run

```

Or in Docker:

```
./test.sh

```

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity43

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.1% 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 ~37 days

Total

18

Last Release

3700d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/296aeff8442778437ea316ca1bd2fb30f87292ba6bfb3d897f292474e2c1075f?d=identicon)[bazilio91](/maintainers/bazilio91)

---

Top Contributors

[![bazilio91](https://avatars.githubusercontent.com/u/380542?v=4)](https://github.com/bazilio91 "bazilio91 (34 commits)")[![bryant1410](https://avatars.githubusercontent.com/u/3905501?v=4)](https://github.com/bryant1410 "bryant1410 (1 commits)")

---

Tags

amqpmysqlphpqueueredisyii2asyncredisrabbitmqyii2AMQPTasks

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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