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

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

vectorial1024/laravel-process-async
===================================

Utilize Laravel Process to run PHP code asynchronously, as if using Laravel Concurrency.

1.0.0(12mo ago)1092[3 issues](https://github.com/Vectorial1024/laravel-process-async/issues)MITPHPPHP ^8.1CI passing

Since Dec 2Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/Vectorial1024/laravel-process-async)[ Packagist](https://packagist.org/packages/vectorial1024/laravel-process-async)[ GitHub Sponsors](https://github.com/Vectorial1024)[ RSS](/packages/vectorial1024-laravel-process-async/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (6)Versions (5)Used By (0)

laravel-process-async
=====================

[](#laravel-process-async)

[![Packagist License](https://camo.githubusercontent.com/59ceffea445bd94c2550b266e206945fe088ff27c27d218acd578850bde89504/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f766563746f7269616c313032342f6c61726176656c2d70726f636573732d6173796e633f7374796c653d706c6173746963)](https://packagist.org/packages/vectorial1024/laravel-process-async)[![Packagist Version](https://camo.githubusercontent.com/bd9b1b52869c9cc45f1a8433d215316974e2567b04d7dbf20216fa72c3e63181/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f766563746f7269616c313032342f6c61726176656c2d70726f636573732d6173796e633f7374796c653d706c6173746963)](https://packagist.org/packages/vectorial1024/laravel-process-async)[![Packagist Downloads](https://camo.githubusercontent.com/cebb59d63fffe5bace0b5967735cdd179038ca279f21bdb59362bf621ed956fd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f766563746f7269616c313032342f6c61726176656c2d70726f636573732d6173796e633f7374796c653d706c6173746963)](https://packagist.org/packages/vectorial1024/laravel-process-async/stats)[![PHP Dependency Version](https://camo.githubusercontent.com/cf7c949f44b0c76a1181bcabc4e25bccc5aa1da5d36d71561d061843fbed483e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f766563746f7269616c313032342f6c61726176656c2d70726f636573732d6173796e632f7068703f7374796c653d706c6173746963266c6162656c3d504850)](https://packagist.org/packages/vectorial1024/laravel-process-async)[![GitHub Repo Stars](https://camo.githubusercontent.com/439642eb26ff7db18f86874c38b332a0fa445af35a778939872cd41e725bbe5a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f766563746f7269616c313032342f6c61726176656c2d70726f636573732d6173796e63)](https://github.com/Vectorial1024/laravel-process-async)

Utilize Laravel Processes to run PHP code asynchronously, as if using Laravel Concurrency.

What really is this?
--------------------

[](#what-really-is-this)

[Laravel Processes](https://laravel.com/docs/10.x/processes) was first introduced in Laravel 10. This library wraps around `Process::start()` to let you execute code in the background to achieve async, albeit with some caveats:

- You may only execute PHP code
- Restrictions from `opis/closure` apply (see [their README](https://github.com/opis/closure))
- Hands-off execution: no built-in result-checking, check the results yourself (e.g. via database, file cache, etc)

This library internally uses an Artisan command to run the async code, which is similar to Laravel 11 [Concurrency](https://laravel.com/docs/11.x/concurrency).

Why should I want this?
-----------------------

[](#why-should-i-want-this)

This library is very helpful for these cases:

- You want a cross-platform minimal-setup async for easy vertical scaling
    - `pthreads` is dead ([source](https://www.php.net/manual/en/intro.pthreads.php))
    - `parallel` is general-purpose and does not have Laravel integration
- You want to start quick-and-dirty async tasks right now (e.g. prefetching resources, pinging remote, etc.)
    - Best is if your task only has very few lines of code
- Laravel 11 [Concurrency](https://laravel.com/docs/11.x/concurrency) is too limiting; e.g.:
    - You want to do something else while waiting for results
    - You want to conveniently limit the max (real) execution time of the concurrent tasks
- And perhaps more!

Of course, if you are considering extreme scaling (e.g. Redis queues in Laravel, multi-worker clusters, etc.) or guaranteed task execution, then this library is obviously not for you.

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

[](#installation)

via Composer:

```
composer require vectorial1024/laravel-process-async
```

This library supports Unix and Windows; see the Testing section for more details.

### Extra requirements for Unix

[](#extra-requirements-for-unix)

If you are on Unix, check that you also have the following:

- GNU Core Utilities (`coreutils`)
    - MacOS do `brew install coreutils`!
    - Other Unix distros should check if `coreutils` is preinstalled

Change log
----------

[](#change-log)

Please see `CHANGELOG.md`.

Example code and features
-------------------------

[](#example-code-and-features)

Tasks can be defined as PHP closures, or (recommended) as an instance of a class that implements `AsyncTaskInterface`.

A very simple example task to write Hello World to a file:

```
// define the task...
$target = "document.txt";
$task = new AsyncTask(function () use ($target) {
    file_put_contents($target, "Hello World!");
});

// if you are using interfaces, then it is just like this:
// $task = new AsyncTask(new WriteToFileTask($target, $message));

// then start it.
$task->start();

// the task is now run in another PHP process, and will not report back to this PHP process.
```

### Task time limits

[](#task-time-limits)

You can set task time limits before you start them, but you cannot change them after the tasks are started. When the time limit is reached, the async task is killed.

The default time limit is 30 real seconds. You can also choose to not set any time limit, in this case the (CLI) PHP `max_execution_time` directive will control the time limit.

Note: `AsyncTaskInterface` contains an implementable method `handleTimeout` for you to define timeout-related cleanups (e.g. write to some log that the task has timed out). This method is still called when the PHP `max_execution_time` directive is triggered.

```
// start with the default time limit...
$task->start();

// start task with a different time limit...
$task->withTimeLimit(15)->start();

// ...or not have any limits at all (beware of orphaned processes!)
$task->withoutTimeLimit()->start();
```

Some tips:

- Don't sleep too long! On Windows, timeout handlers cannot trigger while your task is sleeping.
    - Use short but frequent sleeps instead.
- Avoid using `SIGINT`! On Unix, this signal is reserved for timeout detection.

### Task IDs

[](#task-ids)

You can assign task IDs to tasks before they are run, but you cannot change them after the tasks are started. This allows you to track the statuses of long-running tasks across web requests.

By default, if a task does not has its user-specified task ID when starting, a ULID will be generated as its task ID.

```
// create a task with a specified task ID...
$task = new AsyncTask(function () {}, "customTaskID");

// will return a status object for immediate checking...
$status = $task->start();

// in case the task ID was not given, what is the generated task ID?
$taskID = $status->taskID;

// is that task still running?
$status->isRunning();

// when task IDs are known, task status objects can be recreated on-the-fly
$anotherStatus = new AsyncTaskStatus("customTaskID");
```

Some tips:

- Task IDs can be optional (i.e. `null`) but CANNOT be blank (i.e. `""`)!
- If multiple tasks are started with the same task ID, then the task status object will only track the first task that was started
- Known issue: on Windows, checking task statuses can be slow (about 0.5 - 1 seconds) due to underlying bottlenecks

### Securing the task runners

[](#securing-the-task-runners)

The way this library works means that attackers (or other unwanted parties) may simply craft malicious commands that mimic legitimate usage of this library.

To secure the task runners from being started illegitimately, you may configure the `.env` file to contain the following key:

```
PROCESS_ASYNC_SECRET_KEY=[your secret key here]

```

You may need to clear your Laravel optimisation cache after changing this value.

The contents of the async tasks will be signed by this secret key, so that this library can know whether the tasks are started by this library itself or someone else.

### Fake Objects

[](#fake-objects)

Fake objects are available for users to simulate async task behaviors without actually starting async tasks. This should be helpful when writing tests that attempts to react to task statuses.

The following fake objects are available:

- `FakeAsyncTask`: a fake of `AsyncTask`
- `FakeAsyncTaskStatus`: a fake of `AsyncTaskStatus`

Notably, they can be used like this:

```
// you may obtain the task status in the usual way...
$fakeTask = new FakeAsyncTask(/* ... */, taskID: "TestingTask");
$fakeStatus = $fakeTask->start();

// ...or just construct it directly
$fakeStatusDirect = new FakeAsyncTaskStatus("TestingTask");
// both are the same
assert($fakeStatus == $fakeStatusDirect); // passes

// in your test code, fake task status can be used just like the normal task status:
$fakeStatus->isRunning(); // default returns true

// note: FakeAsyncTaskStatus defaults to "is running" when constructed
// to simulate "task ended", simply do:
$fakeStatus->fakeStopRunning();
// then, the following will return false
$fakeStatus->isRunning(); // returns false
```

Testing
-------

[](#testing)

PHPUnit via Composer script:

```
composer run-script test
```

Latest cross-platform testing results:

RuntimeMacOSUbuntuWindowsLaravel 10 (PHP 8.1)skipped\*skipped\*skipped\*Laravel 11 (PHP 8.2)[![Build-M-L11](https://camo.githubusercontent.com/0a6caa37c68db39eccabbcd847f4b08a1148912047320e4c3f44a15f3630d0e7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f566563746f7269616c313032342f6c61726176656c2d70726f636573732d6173796e632f6d61636f735f6c31312e796d6c3f7374796c653d706c6173746963)](https://github.com/Vectorial1024/laravel-process-async/actions/workflows/macos_l11.yml)[![Build-U-L11](https://camo.githubusercontent.com/3e7ec6fa3b776354cc51fe00a83943aaf7307c388d41fc08133b2caf8b94e1db/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f566563746f7269616c313032342f6c61726176656c2d70726f636573732d6173796e632f7562756e74755f6c31312e796d6c3f7374796c653d706c6173746963)](https://github.com/Vectorial1024/laravel-process-async/actions/workflows/ubuntu_l11.yml)[![Build-W-L11](https://camo.githubusercontent.com/8a8d7d0e6d37a06dc44f0567ac73b2415112c8c50b0dff90a55316afdc68e91d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f566563746f7269616c313032342f6c61726176656c2d70726f636573732d6173796e632f77696e646f77735f6c31312e796d6c3f7374796c653d706c6173746963)](https://github.com/Vectorial1024/laravel-process-async/actions/workflows/windows_l11.yml)Laravel 12 (PHP 8.3)[![Build-M-L12](https://camo.githubusercontent.com/fe5448786b5ed81faa20618d0d7eba881515dbf761e781362ff32ac2f5dca861/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f566563746f7269616c313032342f6c61726176656c2d70726f636573732d6173796e632f6d61636f735f6c31322e796d6c3f7374796c653d706c6173746963)](https://github.com/Vectorial1024/laravel-process-async/actions/workflows/macos_l12.yml)[![Build-U-L12](https://camo.githubusercontent.com/a9447cb990d277546610e5bd2f89b2213585b0c05f25af6c4ba6f05eb6ba6182/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f566563746f7269616c313032342f6c61726176656c2d70726f636573732d6173796e632f7562756e74755f6c31322e796d6c3f7374796c653d706c6173746963)](https://github.com/Vectorial1024/laravel-process-async/actions/workflows/ubuntu_l12.yml)[![Build-W-L12](https://camo.githubusercontent.com/fa391dc61b2fb7dfc17b61837ebb01c376fad9ee6d5d5ee80e063a3e2e729d72/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f566563746f7269616c313032342f6c61726176656c2d70726f636573732d6173796e632f77696e646f77735f6c31322e796d6c3f7374796c653d706c6173746963)](https://github.com/Vectorial1024/laravel-process-async/actions/workflows/windows_l12.yml)Laravel 13 (PHP ???)🛠️🛠️🛠️\*Note: tests for these Laravel versions are skipped because they have old `artisan` file contents:

- It is difficult to mock multi-version `artisan` files for different Laravel versions (see [\#6](https://github.com/Vectorial1024/laravel-process-async/issues/6)).
- It is rare for the `artisan` file at Laravel to be updated
- The actual behavior is expected to be the same.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance47

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity50

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

Total

4

Last Release

364d ago

Major Versions

0.3.0 → 1.0.02025-05-11

### Community

Maintainers

![](https://www.gravatar.com/avatar/c11ba39366ac06b348619a7db14816075a374a8dd6895cbb7016892507dab5bc?d=identicon)[Vectorial1024](/maintainers/Vectorial1024)

---

Top Contributors

[![Vectorial1024](https://avatars.githubusercontent.com/u/17726797?v=4)](https://github.com/Vectorial1024 "Vectorial1024 (198 commits)")

---

Tags

asynclaravelmulti-processingphpasyncconcurrencylaravelmulti-processingprocessjobtaskbackgroundbgspawn

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[iron-io/iron_worker

Client library for IronWorker (multi-language worker platform that runs tasks in the background, in parallel, and at scale.)

57208.5k1](/packages/iron-io-iron-worker)[symplely/coroutine

Cooperative multitasking using generators. The basics of coroutines, async and await!

631.6k2](/packages/symplely-coroutine)[tochka-developers/queue-promises

Promises for Laravel queue jobs

1912.3k](/packages/tochka-developers-queue-promises)

PHPackages © 2026

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