PHPackages                             jjbchunta/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. jjbchunta/async

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jjbchunta/async
===============

Asynchronous code for PHP.

1.2.1(10mo ago)010mitPHP

Since Jun 26Pushed 10mo agoCompare

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

READMEChangelog (7)DependenciesVersions (8)Used By (0)

Asynchronous code for PHP.
==========================

[](#asynchronous-code-for-php)

[![Version](https://camo.githubusercontent.com/1b285b61577d7582789f7fba3bd81460f8da42c05a35fa1aca7e50b40e5c309e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f56657273696f6e2d312e322e312d627269676874677265656e)](https://camo.githubusercontent.com/1b285b61577d7582789f7fba3bd81460f8da42c05a35fa1aca7e50b40e5c309e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f56657273696f6e2d312e322e312d627269676874677265656e)

A wrapper for various built-in non-blocking operations native to PHP, a language notorious for being single-threaded and very much blocking.

This package can be installed via composer:

```
composer require jjbchunta/async

```

Usage
-----

[](#usage)

```
use Jjbchunta\Async\Async;

$promise = new Async( $your_process );

// ...other stuff...

$output = await( $promise );
```

When it comes to this `Async` class, a *"process"* that you pass as the main argument can be one of a few things:

- **cURL Commands** - Preforming a web request using CURL. ex: `"https://api.domain.com -X POST ..."`
- **PHP Files** - Execute a PHP script. ex: `".../path/to/file.php"`

Note

The type of process passed into the `Async` class will be determined on the fly and will be handled accordingly.

### Error handling

[](#error-handling)

If something goes wrong while attempting to initialize the process, rather than something wrong with the process itself, those exceptions are handled by the `AsyncException` class.

```
use Jjbchunta\Async\Async;
use Jjbchunta\Async\AsyncException;

try {
    $promise = new Async( $your_process );
} catch ( AsyncException $e ) {
    // ...something went wrong initializing the process...
}

// ...other stuff...

try {
    $output = await( $promise );
} catch ( Exception $e ) {
    // ...this is an error directly from the process...
}
```

Any other exception relating to the actual execution of the code being run will be thrown as it's respective type when attempting to call the `->wait();` or `->result();` functions.

Also at your disposal...
------------------------

[](#also-at-your-disposal)

Additional function calls available for any `Async` instance.

- `->is_running();` - True / false whether the process is still running.
- `->wait();` - Block the current script from proceeding until the process has finished, returning the result on completion.
- `->stop();` - Forcefully terminate the process.
- `->result();` - Retrieve the result from the last invocation.
- `->rerun();` - Restart the exact same process again.

Sychronous fallback
-------------------

[](#sychronous-fallback)

Different processes require different functionality, and sometimes that functionality is not at the dispoal of the current PHP environment. If that's the case where one of these operations are requested for an asynchronous execution, but the necessary functionality is missing, the main process will be blocking. However, whether sync or async, all code will still work the same regardless. The process will still run and the output will still be the same, and any supporting functions like `->result();` and `->rerun();` will still do what they do and return what they return, just synchronously.

If you're having doubts regarding whether a process can run asynchronously in the current environment, or you'd just like to be sure, you can make a static call to the `Async` class as seen below:

```
Async::can_process_run_async( $your_process );
```

Under the hood
--------------

[](#under-the-hood)

The biggest desire of mine when it comes to this project is for everything to be completely native to PHP with the widest support umbrella. That being the best I can do for a plug-and-play solution to the problem of asynchronous operations inside of a, normally, synchronous language.

As such, this process of achieving "asynchronous" behavior behind the curtain typically comes down to initializing another PHP process where your code or request can run isolated from the main script. Furthermore, some standard I/O pipes will be left open for communication between this parent and child PHP processes for state and output. As for this implementation, it's done using functions like `proc_open`.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](https://github.com/jjbchunta/async/blob/main/CHANGELOG.md) for more information what has changed recently.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/jjbchunta/async/blob/main/LICENSE) for more information.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance54

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

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

Total

7

Last Release

313d ago

### Community

Maintainers

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

---

Top Contributors

[![jjbchunta](https://avatars.githubusercontent.com/u/112114012?v=4)](https://github.com/jjbchunta "jjbchunta (33 commits)")

### Embed Badge

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

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

###  Alternatives

[dasprid/enum

PHP 7.1 enum implementation

379146.0M11](/packages/dasprid-enum)[askvortsov/flarum-categories

Traditional Category Layout for Flarum

2327.3k](/packages/askvortsov-flarum-categories)

PHPackages © 2026

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