saggre / process-manager
A library used to call external binaries with PHP
1.0.0
2025-06-10 16:39 UTC
Requires
- php: >=8.1
Requires (Dev)
- phpunit/phpunit: ^10.5
This package is auto-updated.
Last update: 2025-06-10 16:45:44 UTC
README
A library used to call external binaries with PHP. It provides a simple interface to run processes, handle their input and output, and manage their execution.
Usage
With no output
try{ $result = (new ProcessService('/usr/bin/program')) ->setInput('--version') ->run(); $exitCode = $result->getExitCode(); } catch (ProcessCreateException|ProcessRunException $e) { // TODO: Handle exceptions }
With buffered output
try{ $stdoutStrategy = new BufferedOutputStrategy(); $stderrStrategy = new BufferedOutputStrategy(); $result = (new ProcessService('/usr/bin/program')) ->setStdoutStrategy($stdoutStrategy) ->setStderrStrategy($stderrStrategy) ->setInput('--version') ->run(); $stdout = $stdoutStrategy->getOutput(); $stderr = $stderrStrategy->getOutput(); } catch (ProcessCreateException|ProcessRunException $e) { // TODO: Handle exceptions }
With streamed output
try{ $stdoutStrategy = new StreamedOutputStrategy( fn(string $data) => print $data )->setChunkLength(128); $result = (new ProcessService('/usr/bin/program')) ->setStdoutStrategy($stdoutStrategy) ->setInput('--version') ->run(); } catch (ProcessCreateException|ProcessRunException $e) { // TODO: Handle exceptions }