PHPackages                             terremoth/php-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. terremoth/php-async

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

terremoth/php-async
===================

Write async PHP processes or process async files with no phtreads, parallel or reactive libs

v1.0.7(4mo ago)3318[7 issues](https://github.com/terremoth/php-async/issues)GPL-3.0-or-laterPHPPHP ^8.2CI failing

Since Dec 1Pushed 3mo ago1 watchersCompare

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

READMEChangelog (8)Dependencies (7)Versions (9)Used By (0)

PHP Async Process
=================

[](#php-async-process)

Process functions or files **async** and in **parallel** without needing AMP, ReactPHP, RxPHP, Spatie/Fork, Fibers, Pthreads, Parallel, Revolt, Pcntl or Swoole.

Just raw PHP! It is magic! This is **not** the classical meaning of async like python's or nodejs you're addicted to hear. This is more like an "Async Process", or "Async Multitasking", but you can achieve the same results you expect. Enjoy.

[![codecov](https://camo.githubusercontent.com/13a7a2f01bcd2aee83b29afdd9dbd1176251192a5ea4a57e43a596bd60a19892/68747470733a2f2f636f6465636f762e696f2f67682f74657272656d6f74682f7068702d6173796e632f67726170682f62616467652e7376673f746f6b656e3d57333756354544455251)](https://codecov.io/gh/terremoth/php-async)[![Code Coverage](https://camo.githubusercontent.com/1ca97440e9e0be92437f262f18f1d633592ef5769fcd3a0da9b3d7e69e20ba0f/68747470733a2f2f716c74792e73682f67682f74657272656d6f74682f70726f6a656374732f7068702d6173796e632f636f7665726167652e737667)](https://qlty.sh/gh/terremoth/projects/php-async)[![Psalm type coverage](https://camo.githubusercontent.com/104e5e7235041153809ccdcf641854d76e55bf895a8a463bddec63c32396c5b5/68747470733a2f2f73686570686572642e6465762f6769746875622f74657272656d6f74682f7068702d6173796e632f636f7665726167652e737667)](https://shepherd.dev/github/terremoth/php-async)[![Psalm level](https://camo.githubusercontent.com/b9ed3933a94247150ee6867b9bc5efae2402a7f954dad423917f9dd440e3ed6e/68747470733a2f2f73686570686572642e6465762f6769746875622f74657272656d6f74682f7068702d6173796e632f6c6576656c2e737667)](https://shepherd.dev/github/terremoth/php-async)[![Test Run Status](https://github.com/terremoth/php-async/actions/workflows/workflow.yml/badge.svg?branch=main)](https://github.com/terremoth/php-async/actions/workflows/workflow.yml)[![Codacy Badge](https://camo.githubusercontent.com/ab3c431b555d5f0ce5ac0e83eddad2570a2efc9f0435be6f748d0332874883fa/68747470733a2f2f6170702e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f3437386164616463393439633433623039306662323234313765383332333236)](https://app.codacy.com/gh/terremoth/php-async/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)[![Maintainability](https://camo.githubusercontent.com/529436d65601fb1773eece85ad42671c5c0c980fb25a91cf82f66bf46fd84e47/68747470733a2f2f716c74792e73682f67682f74657272656d6f74682f70726f6a656374732f7068702d6173796e632f6d61696e7461696e6162696c6974792e737667)](https://qlty.sh/gh/terremoth/projects/php-async)[![License](https://camo.githubusercontent.com/1a291fbddf43e9388ebc42e4da1bfa23a7a33769209e60886ad1181954337c3c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f74657272656d6f74682f7068702d6173796e632e7376673f6c6f676f3d6c67706c26636f6c6f723d343162623133)](https://github.com/terremoth/php-async/blob/main/LICENSE)[![Latest Stable Version](https://camo.githubusercontent.com/549d5088a45ef9f7d6d05f2ee8c1cf6ca04db068863b98445889883fe69e4c64/68747470733a2f2f706f7365722e707567782e6f72672f74657272656d6f74682f7068702d6173796e632f762f737461626c65)](https://packagist.org/packages/terremoth/php-async)[![Dynamic JSON Badge](https://camo.githubusercontent.com/eb4213f17d0377c12d16de72a061b9700a74123e48a50ab9975e45685be6ce14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f64796e616d69632f6a736f6e3f75726c3d6874747073253341253246253246646973636f72642e636f6d253246617069253246696e76697465732532464a7846684d5657753832253346776974685f636f756e7473253344747275652671756572793d2532342e617070726f78696d6174655f6d656d6265725f636f756e74266c6f676f3d646973636f7264266c6f676f436f6c6f723d7768697465266c6162656c3d5573657273253230546f74616c26636f6c6f723d677265656e)](https://discord.gg/JxFhMVWu82)[![Packagist Downloads](https://camo.githubusercontent.com/c8aed7f6bdb649e8e7c53bd62f600d34a454baa1a3be9aeab8912920433b5913/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f74657272656d6f74682f7068702d6173796e633f636f6c6f723d343162623133)](https://camo.githubusercontent.com/c8aed7f6bdb649e8e7c53bd62f600d34a454baa1a3be9aeab8912920433b5913/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f74657272656d6f74682f7068702d6173796e633f636f6c6f723d343162623133)

### Target Audience

[](#target-audience)

For those who, for some reason, cannot or don't want to use Swoole or Parallel

### Why?

[](#why)

- Native way + no need to change php.ini
- Easy: just composer install the lib and use it
- Fast to learn
- Fast to use: no need to compile, no need to download pecl extensions
- Operating system agnostic

### How?

[](#how)

It uses a combination of:

- serializable-clojure lib
- Symfony/Process lib
- and PHP's native Shmop extension (available in any platform)

First it serializes your closure with its code,
Then it sends to another *background* process to execute, through [shmop](https://www.php.net/manual/en/ref.shmop.php)

#### Some Possible Use Cases

[](#some-possible-use-cases)

- You got some user data and want to do a heavy processing somewhere without blocking;
- You want to send an email in your own platform without blocking with some data you got before;
- You want to create tons of processes at the same time, not blocking the main process/thread;
- Something will be heavy processed and will took time but your user does not need to know that at the time and don't need/want to wait;

#### Warning

[](#warning)

it does not works on MSYS or MINGW shells! However, It will work fine on both Windows (cmd and powershell) and Linux.

See [demos/demo.php](demos/demo.php) for examples.

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

[](#installation)

```
composer require terremoth/php-async
```

Documentation
-------------

[](#documentation)

```
