react/child-process
Event-driven child process execution for ReactPHP. Start and manage processes from the event loop, stream STDIN/STDOUT/STDERR via React streams, send signals, and receive exit events. Supports custom pipes and Windows considerations.
Install the package via Composer: composer require react/child-process. Start by reading the Quickstart example in the README — it’s minimal and demonstrates the core pattern: create a Process, call start(), attach data listeners to stdout/stderr, and handle the exit event. First use case: run a simple command (e.g., php artisan list) and stream its output without blocking the EventLoop. Avoid complex shell constructs initially; use escapeshellarg() when passing user input or paths with spaces.
$process->stdout, $process->stdin, $process->stderr for async data handling (e.g., on('data'), on('end')). Use $process->stdin->write() to stream input interactively (e.g., for REPL-like tools or long-running processes).cmd1 && cmd2), start processes sequentially using exit events to maintain fine-grained control and error handling:
$p1 = new Process('build');
$p1->start();
$p1->on('exit', fn() => $p2 = new Process('test')->start());
$process->terminate($signal) for graceful shutdowns. For robust cleanup, close all pipes ($process->pipes) before sending signals to prevent zombie processes or lingering descriptors.exec on Unix to avoid the shell wrapper (e.g., exec sleep 5) — improves PID accuracy and signal targeting.stderr alongside stdout to catch errors without exit code parsing; use Loop::addTimer() for timeouts with explicit termination logic.sh -c unless prefixed with exec. This means signals target the shell (PID ≠ child PID), and pipes inherit to sub-processes — often causing termination issues. Always test signal behavior in your environment.stdout/stderr for real-time streaming on Windows; consider alternatives like log files. Use cmd /c explicitly for shell built-ins.pipe() or manual pause()), the process may not detect termination. Always resume or close pipes before expecting exit.proc_open() format. Misconfigured pipes (e.g., missing 0, 1, 2) can cause $stdin/$stdout properties to be unset.drain events on stdin when writing large payloads:
$process->stdin->on('drain', fn() => $process->stdin->write('...'));
composer.json for version pins).How can I help you explore Laravel packages today?