greendrake / php-asyncprocess
ReactPHP Promise implementation for truly asynchronous background processes
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/greendrake/php-asyncprocess
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"