Pletfix Process class starts a backround process using PHP's [proc_open] (

Create a Process Instance

You may use the process() function to create a process:

$process = process('ls - l');

You could set environment variables, e.g. like this:

$env = config('app.debug') ? ['XDEBUG_CONFIG' => 'idekey=PHPSTORM'] : null;

$process = process($cmd, $env);   

Of course, you can redirect the output in the conventional way, e.g. into a file:

$process = process($cmd . ' > output.txt 2>&1');

Or to Nirvana:

$process = process($cmd . ' > /dev/null 2>&1');

If you still want the process to run in the background after the HTTP request is completed, add a &:

$process = process($cmd . ' > /dev/null 2>&1 &');

Available Methods

Method Listing


The run method runs a process:

$exitcode = $process->run();

You may set a timeout in seconds to wait until the process is finished:

$exitcode = $process->run(60);

Note, that the command sequence below are the same as $process->run():

$exitcode = $process->wait();


The start method starts a background process:



The wait method waits for the process to terminate:

$exitcode = $process->wait();

You may set a timeout in seconds or null to disable:

$exitcode = $process->wait(60);


The terminate method terminates the process:


This optional parameter is only useful on POSIX operating systems; you may specify a signal to send to the process using the kill(2) system call. The default is SIGTERM (15).

SIGTERM (15) is the termination signal. The default behavior is to terminate the process, but it also can be caught or ignored. The intention is to kill the process, but to first allow it a chance to cleanup.

SIGKILL (9) is the kill signal. The only behavior is to kill the process, immediately. As the process cannot catch the signal, it cannot cleanup, and thus this is a signal of last resort.



The kill method kills the process immediately. It's a short way to invoke $process->terminate(SIGKILL):



The read method reads a line from STDOUT:

$line = $process->read();


The write method writes a line to STDIN:



The getOutput method gets the output from STDOUT when the process is finished:

$output = $process->getOutput();


The getErrorOutput method gets the error output from STDERR when the process is finished:

$error = $process->getErrorOutput();    


The isRunning method determines if the process is currently running:



The getExitCode method gets the exit code returned by the process:

$exitcode = $process->getExitCode();


The isSuccessful method determines if the process ended successfully:

$ok = $process->isSuccessful();

(edit on GitHub)