Skip to main content

Introduction

Laravel’s Process facade is a thin wrapper around the Symfony Process component. It provides a clean, expressive API for invoking external processes from your application.

Invoking processes

Use Process::run() to execute a command synchronously and wait for it to finish.
The returned ProcessResult instance exposes several inspection methods:

Throwing on failure

To throw an Illuminate\Process\Exceptions\ProcessFailedException when a process fails, use throw() or throwIf(). If the process succeeded, the ProcessResult instance is returned.

Process options

Working directory

Use path() to set the working directory. If omitted, the process inherits the directory of the currently executing PHP script.

Standard input

Pass data to the process via standard input using input().

Timeouts

Processes time out after 60 seconds by default, throwing a ProcessTimedOutException. Override with timeout().
You can also pass a CarbonInterval helper function:
To disable the timeout entirely, use forever().
Set an idle timeout (maximum seconds with no output) with idleTimeout().

Environment variables

Provide environment variables with env(). The process also inherits all system environment variables.
Pass false to remove an inherited variable.

Disabling output

When you don’t need the output, call quietly() to conserve memory.

Real-time output

Pass a closure as the second argument to run() to receive output as it is produced.

Pipelines

Process::pipe() lets you chain commands so that the output of one becomes the input of the next. The result of the last command in the pipeline is returned.
You can also pass an array of command strings.
Assign string keys with as() to identify each process’s output in the closure.

Asynchronous processes

Process::start() launches a process without waiting for it to finish, allowing your application to do other work in the meantime.

Process IDs and signals

Retrieve the OS-assigned process ID with id().
Send a signal to the running process with signal().

Asynchronous output

While the process is running, use latestOutput() and latestErrorOutput() to read new output since the last check.
Wait until a specific string appears in the output using waitUntil().

Checking for timeouts

Call ensureNotTimedOut() inside a loop to throw a timeout exception if the process has exceeded its timeout.

Concurrent processes

Process::pool() runs multiple processes in parallel.
Process::concurrently() is a shorthand that starts the pool and immediately waits for all results.

Naming pool processes

Use as() to assign string keys and access results by name.
Send a signal to every process in the pool at once.

Testing

Faking processes

Call Process::fake() to prevent any real processes from running during tests.
Specify output and exit codes for faked processes.

Faking specific processes

Use command patterns as keys to fake individual commands differently.

Faking sequences

Return different results for repeated calls to the same command.

Assertions

Preventing stray processes

Call Process::preventStrayProcesses() to throw an exception when a process runs without a matching fake.

Artisan console

Create custom commands that invoke processes

Queues

Compare with queue-based async processing
Last modified on April 13, 2026