agussuroyo / async
A simple asynchronous process manager for PHP using pcntl.
1.0.0
2025-03-19 06:24 UTC
Requires
- php: >=7.4
Requires (Dev)
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2025-06-20 03:17:59 UTC
README
A lightweight and efficient PHP package to manage asynchronous processes with a configurable process limit.
Installation
Install via Composer:
composer require agussuroyo/async
Features
- Asynchronous process execution with
pcntl_fork
- Configurable maximum number of parallel processes
- Automatic CPU core detection for optimal performance
- Efficient child process management
Usage
Basic Example
use AgusSuroyo\Async\Async; $async = new Async(); $async->run(function () { sleep(2); echo "Process 1 done\n"; }); $async->run(function () { sleep(3); echo "Process 2 done\n"; }); $async->wait();
Setting Maximum Concurrent Processes
$async = new Async(2); // Limit to 2 concurrent processes
Dynamic Max Process Control
$async = new Async(); $async->max(4); // Adjust max processes at runtime
Testing
Run the tests using PHPUnit:
vendor/bin/phpunit
Contributing
Contributions are welcome! Please submit a pull request or open an issue.
License
This package is open-source and available under the MIT License.