greendrake / php-asyncprocess
ReactPHP Promise implementation for truly asynchronous background processes
1.0.0
2023-10-14 23:31 UTC
Requires
- php: >=8.2.0
- react/async: 4.x-dev
- react/http: 1.x-dev
- react/promise: 3.x-dev
Requires (Dev)
- phpunit/phpunit: 10
README
ReactPHP Promise implementation for truly asynchronous background processes.
This library allows to run commands in background shaped as ReactPHP Promises. Non-blocking. Tested on Linux only.
Under the hood, it works this way:
-
A child process is forked using pcntl_fork. This runs the specified command and reports the result back to the parent process via a local HTTP call (using a one-off reactphp/http server/client).
-
Once the parent process gets the result, it fulfils (or rejects, depending on the exit code) the Promise. Profit.
Example:
use function React\Async\await; $p = new \Greendrake\AsyncProcess\Promise('a=$( expr 10 - 3 ); echo $a'); // Kick off the process in background. $result = await($p->get()); // Get the instance of React\Promise\Promise, wait for it to resolve. echo $result; // outputs "7"