agussuroyo / async
A simple asynchronous process manager for PHP using pcntl.
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/agussuroyo/async
Requires
- php: >=7.4
Requires (Dev)
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2025-10-20 04:05:25 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.