illuminate/process
Illuminate Process provides a fluent API to run and manage system processes in Laravel. Start commands, stream output, handle timeouts, work in specific directories, set env vars, capture results, and integrate cleanly with other Illuminate components.
Install via Composer:
composer require illuminate/process
This package is typically auto-registered in Laravel 10+ (no service provider needed). Use it immediately in tinker, commands, or jobs:
use Illuminate\Process\Factory as ProcessFactory;
$process = app(ProcessFactory::class)->run('composer validate');
if ($process->successful()) {
echo "Valid!"; // or $process->output();
}
Key entry points: app(ProcessFactory::class), Process::fake(), or the Process facade (if aliased). Start with run() for simple blocking calls, and start() for interactive/streaming workflows.
run('php artisan ...') over shell_exec()—handles escaping, avoids shell injection, and provides structured return values.start() with callbacks for long tasks (e.g., npm build, database migrations):
Process::start('npm run build', function ($type, $buffer) {
if ($type === Process::OUT) write_to_log($buffer);
})->wait();
batch() for concurrency:
Process::batch([
fn() => Process::run('build:svg'),
fn() => Process::run('build:css'),
])->timeout(120)->run();
for() to apply environment or directory defaults across related commands:
$builder = Process::for('deploy')->path(base_path('deploy-scripts'));
$builder->run('init');
$builder->run('migrate');
wkhtmltopdf) while managing timeouts securely.throw() is opt-in: Non-zero exit codes return $process->failed() as true—explicitly call ->throw() to throw exceptions (avoids silent failures).shell: false for security in start()/run() if avoiding shell interpretation:
Process::run(['php', 'script.php'], timeout: 10, shell: false);
->lineLength(0)) and validate input—unbounded buffering risks memory exhaustion.->tty(true) may hang or fail; reserve for CLI contexts.Process::fake([
'npm run build' => Process::result(
output: 'Build successful',
errorOutput: '',
exitCode: 0
),
]);
.timeout() applies to each process in a batch; use ->timeout() on the batch itself for overall limit.->withoutTimeout() during local dev to avoid intermittent failures—but never in production.C:\path\to\file); use forward slashes or str_replace('\\', '/', $path).How can I help you explore Laravel packages today?