Laravel Async is a package that provides a straightforward way to run code asynchronous and parallel based on the Spatie Async wrapper for the Laravel application. You can install the Laravel Async package by using Composer: composer require vxm/laravel-async
You can publish the config file (optional) with: php artisan vendor:publish --provider="VXM\Async\AsyncServiceProvider" --tag="config" After installation, now you can try running async code via the Async facade: use Async; for ($i = 1; $i function ($output) { // `$output` of job in this case is `123`.
}, ]); // 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']]); This package has many great features and options available with code examples.