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

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

vxm/laravel-async
=================

Provide an easy way to run code asynchronously for Laravel

v5.0.0(1y ago)157337.0k↓31.1%28[9 issues](https://github.com/vuongxuongminh/laravel-async/issues)[1 PRs](https://github.com/vuongxuongminh/laravel-async/pulls)1MITPHPPHP ^8.1CI failing

Since Jun 12Pushed 1y ago5 watchersCompare

[ Source](https://github.com/vuongxuongminh/laravel-async)[ Packagist](https://packagist.org/packages/vxm/laravel-async)[ Docs](https://github.com/vuongxuongminh/laravel-async)[ RSS](/packages/vxm-laravel-async/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (14)Used By (1)

 [ ![](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://github.com/vuongxuongminh/laravel-async/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/vuongxuongminh/laravel-async/actions/workflows/tests.yml) [![](https://camo.githubusercontent.com/f6a35a00afd85fcbf94809d82186809c1812035976a851896c9b532d3ee89066/68747470733a2f2f636f6465636f762e696f2f6769746875622f76756f6e6778756f6e676d696e682f6c61726176656c2d6173796e632f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d3846315a544642324333)](https://codecov.io/github/vuongxuongminh/laravel-async) [![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 vxm/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 [
    /*
     * The PHP binary will be use in async processes.
     */
    'withBinary' => PHP_BINARY,

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

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

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

    /*
     * Default output length of async processes.
     */
    'defaultOutputLength' => 1024 * 10,

    /*
     * 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 VXM\Async\AsyncFacade as Async;

for ($i = 1; $i < 20; $i++) {
    Async::run(function () use ($i) {
        sleep(1);

        return $i;
    });
}

var_dump(implode(', ', Async::wait()));

// Output value may be like:
// string(65) "5, 2, 1, 14, 4, 6, 7, 8, 19, 16, 12, 18, 13, 3, 10, 9, 11, 17, 15"
```

An async job can be callable class, anonymous function or Laravel callback:

```
use VXM\Async\AsyncFacade as 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 VXM\Async\AsyncFacade as 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');

// Another way:

Async::batchRun(
    'Your\AsyncJobs\Class@jobA',
    'Your\AsyncJobs\Class@jobB',
    'Your\AsyncJobs\Class@jobC',
    '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 VXM\Async\AsyncFacade as 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'
]);

Async::batchRun(
    ['AsyncJobClassA@handleMethod', ['success' => 'AsyncJobEventListenerA@handleSuccess']],
    ['AsyncJobClassB@handleMethod', ['success' => 'AsyncJobEventListenerB@handleSuccess']],
    ['AsyncJobClassC@handleMethod', ['success' => 'AsyncJobEventListenerC@handleSuccess']]
);
```

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 VXM\Async\AsyncFacade as Async;
use App\MyModel;
use App\AsyncJobs\MyJob;

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

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

// or batch run with multiple models:

$model2 = App\MyModel::find(2);

Async::batchRun(
    new MyJob($model),
    new MyJob($model2)
);
```

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

49

—

FairBetter than 95% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity52

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 92.4% 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 ~153 days

Recently: every ~190 days

Total

13

Last Release

690d ago

Major Versions

1.1.1 → 2.0.02020-05-14

2.2.0 → 3.0.02023-01-27

3.0.0 → 4.0.02023-07-16

v4.1.0 → v5.0.02024-06-27

PHP version history (4 changes)1.0.0PHP ^7.1

2.0.0PHP ^7.2

2.1.0PHP ^7.2 || ^8.0

3.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/8901d64a1059726b851dbdd91463ad1d3169f9dba6a2dcff11d05f97d9bccaea?d=identicon)[vuongxuongminh](/maintainers/vuongxuongminh)

---

Top Contributors

[![vuongxuongminh](https://avatars.githubusercontent.com/u/38932626?v=4)](https://github.com/vuongxuongminh "vuongxuongminh (97 commits)")[![mbardelmeijer](https://avatars.githubusercontent.com/u/1583095?v=4)](https://github.com/mbardelmeijer "mbardelmeijer (3 commits)")[![peteradeojo](https://avatars.githubusercontent.com/u/60135915?v=4)](https://github.com/peteradeojo "peteradeojo (3 commits)")[![fmarquesto](https://avatars.githubusercontent.com/u/16501896?v=4)](https://github.com/fmarquesto "fmarquesto (2 commits)")

---

Tags

laravellaravel-asynclaravel-packagevxmlaravel-async

###  Code Quality

Code StyleECS

### Embed Badge

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

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

###  Alternatives

[illuminate/bus

The Illuminate Bus package.

6043.8M409](/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)[saeedvaziry/laravel-async

Run asynchronous code in Laravel without waiting for results

15310.0k](/packages/saeedvaziry-laravel-async)[palpalani/laravel-sqs-queue-json-reader

Custom SQS queue reader for Laravel

26109.8k](/packages/palpalani-laravel-sqs-queue-json-reader)

PHPackages © 2026

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