PHPackages                             khoivan/laravel-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. khoivan/laravel-async

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

khoivan/laravel-async
=====================

Provide an easy way to run code asynchronously for Laravel

1.1.1(6y ago)06MITPHPPHP ^7.1

Since Jun 12Pushed 6y agoCompare

[ Source](https://github.com/khoivan/laravel-async)[ Packagist](https://packagist.org/packages/khoivan/laravel-async)[ Docs](https://github.com/khoivan/laravel-async)[ RSS](/packages/khoivan-laravel-async/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (5)Versions (5)Used By (0)

 [ ![](https://avatars0.githubusercontent.com/u/958072) ](https://github.com/laravel)

Laravel Async
=============

[](#laravel-async)

 [![Latest version](https://camo.githubusercontent.com/3f47e4a03c54232c9f6dd1af8126285c73d38c96f5074080c2436e4efc8f9d19/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f76786d2f6c61726176656c2d6173796e632e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/vxm/laravel-async) [![Build status](https://camo.githubusercontent.com/8e4670ea8da6396d79589c8ecdf3b502514831bea82c71b1f9cc252a4091949c/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f76756f6e6778756f6e676d696e682f6c61726176656c2d6173796e632f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/vuongxuongminh/laravel-async) [![Quantity score](https://camo.githubusercontent.com/300fc8cb00a777064feb23225229b42cb88b71bd93996966d9a3259ce57f9abb/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f76756f6e6778756f6e676d696e682f6c61726176656c2d6173796e632e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/vuongxuongminh/laravel-async) [![StyleCI](https://camo.githubusercontent.com/a609c815061a72c877fc4bf79d668f6d1053c46eb52d65c08ffa6768da9a296e/68747470733a2f2f7374796c6563692e696f2f7265706f732f3139313033313231302f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/191031210) [![Total download](https://camo.githubusercontent.com/cf933c6f518e01bfe2da9600300498bcacf076c09ad867c4efd126d0e2098b96/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f76786d2f6c61726176656c2d6173796e632e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/vxm/laravel-async) [![License](https://camo.githubusercontent.com/4cb018212f8f7cbe4d2914848f60b359ad59264681a510586052fd392795278e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f76786d2f6c61726176656c2d6173796e632e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/vxm/laravel-async)

About it
--------

[](#about-it)

A package provide an easy way to run code asynchronous and parallel base on [Spatie Async](https://github.com/spatie/async) wrapper for Laravel application.

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

[](#installation)

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

```
composer require khoivan/laravel-async
```

The package will automatically register itself.

You can publish the config-file (optional) with:

```
php artisan vendor:publish --provider="VXM\Async\AsyncServiceProvider" --tag="config"
```

This is the contents of the published config file:

```
return [
    /**
     * Maximum concurrency async processes.
     */
    'concurrency' => 20,

    /**
     * Async process timeout.
     */
    'timeout' => 15,

    /**
     * Sleep (micro-second) time when waiting async processes.
     */
    'sleepTime' => 50000,

    /**
     * An autoload script to boot composer autoload and Laravel application.
     * Default null meaning using an autoload of this package.
     */
    'autoload' => null,
];
```

Usage
-----

[](#usage)

### Run async code

[](#run-async-code)

After install, now you can try run async code via `Async` facade:

```
use Async;

// run with anonymous function:
Async::run(function() {
    // Do a thing
});

// run with class@method
Async::run('Your\AsyncJobs\Class@handle');

// call default `handle` method if method not set.
Async::run('Your\AsyncJobs\Class');
```

You can run multiple job one time and waiting until all done.

```
use Async;

Async::run('Your\AsyncJobs\Class@jobA');
Async::run('Your\AsyncJobs\Class@jobB');
Async::run('Your\AsyncJobs\Class@jobC');
Async::run('Your\AsyncJobs\Class@jobD');

$results = Async::wait(); // result return from jobs above
```

### Event listeners

[](#event-listeners)

When creating asynchronous processes, you can add the following event hooks:

```
use Async;

Async::run(function () {

    return 123;
}, [
    'success' => function ($output) {
        // `$output` of job in this case is `123`.
    },
    'timeout' => function () {
        // A job took too long to finish.
    },
    'error' => function (\Throwable $exception) {
        // When an exception is thrown from job, it's caught and passed here.
    },
]);

// Another way:
Async::run('AsyncJobClass@handleMethod', [
    'success' => 'AsyncJobEventListener@handleSuccess',
    'timeout' => 'AsyncJobEventListener@handleTimeout',
    'error' => 'AsyncJobEventListener@handleError'
]);
```

Working with complex job
------------------------

[](#working-with-complex-job)

When working with complex job you may want to setup more before it run (ex: job depend on Eloquent model). This package provide you an Artisan command `make:async-job` to generate a job template. By default, all of the async jobs for your application are stored in the `app/AsyncJobs` directory. If the `app/AsyncJobs` directory doesn't exist, it will be created. You may generate a new async job using the Artisan CLI:

```
php artisan make:async-job MyJob
```

After created it, you need to prepare your job structure, example:

```
namespace App\AsyncJobs;

use App\MyModel;
use VXM\Async\Invocation;
use App\MyHandleDependency;
use Illuminate\Queue\SerializesModels;

class MyJob
{

    use Invocation;
    use SerializesModels;

    protected $model;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(MyModel $model)
    {
        $this->model = $model;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle(MyHandleDependency $dependency)
    {
        //
    }
}
```

In this example, note that we were able to pass an Eloquent model directly into the async job's constructor. Because of the `SerializesModels` trait that the job is using, Eloquent models will be gracefully serialized and unserialized when the job is processing. If your async job accepts an Eloquent model in its constructor, only the identifier for the model will be serialized onto the queue. When the job is actually handled, the system will automatically re-retrieve the full model instance from the database. It's all totally transparent to your application and prevents issues that can arise from serializing full Eloquent model instances.

The `handle` method is called when the job is processed in async process. Note that we are able to type-hint dependencies on the handle method of the job. The Laravel service container automatically injects these dependencies.

If you would like to take total control over how the container injects dependencies into the handle method, you may use the container's `bindMethod` method. The `bindMethod` method accepts a callback which receives the job and the container. Within the callback, you are free to invoke the handle method however you wish. Typically, you should call this method from a service provider:

```
use App\AsyncJobs\MyJob;
use App\MyHandleDependency;

$this->app->bindMethod(MyJob::class.'@handle', function ($job, $app) {
    return $job->handle($app->make(MyHandleDependency::class));
});
```

Now run it asynchronously:

```
use Async;
use App\MyModel;
use App\AsyncJobs\MyJob;

$model = App\MyModel::find(1);

Async::run(new MyJob($model));
```

Compare with queue
------------------

[](#compare-with-queue)

You can feel this package look like queue and thing why not using queue?

Queue is a good choice for common async jobs. This package using in cases end-user need to get response in single request but it's a heavy things need to using several processes for calculation or IO heavy operations. And it no need to run a queue listener.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity57

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

Total

3

Last Release

2277d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/04f3b3b09cc6732f12cbc001ae247558f5ba415120c1c675222fa79f5084369a?d=identicon)[khoivan](/maintainers/khoivan)

---

Top Contributors

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

---

Tags

laravel-asynckhoivan

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/khoivan-laravel-async/health.svg)

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

###  Alternatives

[illuminate/queue

The Illuminate Queue package.

20331.4M1.2k](/packages/illuminate-queue)[vxm/laravel-async

Provide an easy way to run code asynchronously for Laravel

157337.0k1](/packages/vxm-laravel-async)[illuminate/bus

The Illuminate Bus package.

6043.8M407](/packages/illuminate-bus)[stancl/jobpipeline

Turn any series of jobs into Laravel listeners.

1226.6M10](/packages/stancl-jobpipeline)[prwnr/laravel-streamer

Events streaming package for Laravel that uses Redis 5 streams

110196.9k1](/packages/prwnr-laravel-streamer)[harris21/laravel-fuse

Circuit breaker for Laravel queue jobs. Protect your workers from cascading failures.

3786.5k](/packages/harris21-laravel-fuse)

PHPackages © 2026

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