saggre/process-manager

A library used to call external binaries with PHP

1.0.0 2025-06-10 16:39 UTC

This package is auto-updated.

Last update: 2025-08-03 23:11:56 UTC


README

Codecov FOSSA Status

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/node'))
                ->setInput('--version')
                ->run();
    
    echo $result->getExitCode();
    // 0
} catch (ProcessCreateException|ProcessRunException $e) {
    // TODO: Handle exceptions
}

With buffered output

try{
    $stdoutStrategy = new BufferedOutputStrategy();

    $result = (new ProcessService('/usr/bin/node'))
                ->setStdoutStrategy($stdoutStrategy)
                ->setInput('--version')
                ->run();
    
    echo $stdoutStrategy->getOutput();
    // v22.16.0
} catch (ProcessCreateException|ProcessRunException $e) {
    // TODO: Handle exceptions
}

With streamed output

try{
    $stdoutStrategy = new StreamedOutputStrategy(
        fn(string $data) => print $data
        // v22.16.0
    )->setChunkLength(128);

    $result = (new ProcessService('/usr/bin/node'))
                ->setStdoutStrategy($stdoutStrategy)
                ->setInput('--version')
                ->run();
} catch (ProcessCreateException|ProcessRunException $e) {
    // TODO: Handle exceptions
}

License

FOSSA Status