Download the PHP package agussuroyo/async without Composer
On this page you can find all versions of the php package agussuroyo/async. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download agussuroyo/async
More information about agussuroyo/async
Files in agussuroyo/async
Package async
Short Description A simple asynchronous process manager for PHP using pcntl.
License MIT
Informations about the package async
agussuroyo/async
Run PHP work in parallel by forking child processes. Each task returns a Future that resolves to the callback's return value — or rethrows its exception in the parent.
Requirements
- PHP 7.4 – 8.4
pcntlextension
pcntl is unavailable on native Windows and disabled in most non-CLI SAPIs (php-fpm, mod_php). This library is for CLI scripts and long-running daemons.
Install
Quick start
Concurrent fan-out
Children run in parallel up to the concurrency limit. Their await() order doesn't matter — each future resolves whenever its child finishes.
Errors propagate
If the original exception class's constructor isn't (string $message, int $code)-compatible, the parent rethrows as RuntimeException with the original class name embedded in the message. The child stack trace is preserved either way.
Concurrency limit
Default is CPU cores × 2. Override at construction or at runtime:
When the limit is reached, run() blocks until a slot frees up.
Fire-and-wait
If you don't need individual return values, ignore the futures and call wait():
Caveats
- Return values must be
serialize()-safe. They cross the fork via a Unix socket pipe. Resources (PDO connections, sockets, file handles) can't ride the channel — return scalars, arrays, or value objects. - No shared state across children. Each fork gets a copy-on-write snapshot of the parent's memory; mutations in the child stay in the child.
- No event-loop integration. This is a cooperative scheduler that pumps inside
wait()andFuture::await(). Use a dedicated event loop (Revolt/Amp/ReactPHP) if you need async I/O.
Testing
License
MIT.