symfony/process
Symfony Process executes system commands in isolated subprocesses with robust control over input/output, environment variables, timeouts, signals, and errors. Ideal for running CLI tools safely, streaming output, and integrating background tasks in PHP apps.
Build vs. Buy Decision: Justify adopting Symfony Process over rolling custom subprocess solutions (e.g., shell_exec, exec, or proc_open wrappers). The package’s active maintenance (e.g., fixes for array env vars, Windows MSYS escaping) and Symfony’s ecosystem integration reduce technical debt and security risks. Ideal for teams prioritizing scalability and maintainability over one-off scripts.
Feature Enablement for CLI/DevOps Workflows:
['KEY' => ['val1', 'val2']]) to subprocesses, enabling use cases like:
proc_open limits, CGI/FastCGI leaks) to ensure consistent behavior across CI/CD pipelines (GitHub Actions, GitLab CI, self-hosted runners).Roadmap Alignment:
Process::fromShellCommandline() for Messenger integration)..env arrays to deployment scripts).Cost Efficiency:
Security and Compliance:
proc_open and Windows limits improve reliability in shared hosting or containerized environments.Adopt symfony/process when:
docker build --build-arg ARRAY=...) or triggering Kubernetes jobs with dynamic parameters.Look elsewhere if:
putenv).pcntl or proc_open directly).fromShellCommandline).proc_open/env enhancements.*"Symfony Process v8.1.0-BETA2 is a strategic upgrade that lets us safely and flexibly execute external commands—now with beta support for PHP 8.1+ and enhanced environment variable handling. Here’s the business case:
Key Use Cases:
['BUILD_ARGS' => ['--arg1', '--arg2']]).Upgrade Path: Simple composer require symfony/process:^8.1—compatible with Laravel. Let’s adopt this to cut costs, reduce risk, and enable modern PHP features while scaling."*
*"This v8.1.0-BETA2 release adds array environment variables and PHP 8.1+ support, making it the best time to migrate from custom subprocess solutions. Here’s what’s new and why it matters:
New Features:
['KEY' => ['val1', 'val2']]) for tools like Docker or Kubernetes.
$process = new Process(['docker', 'build'], [
'BUILD_ARGS' => ['--arg1=val1', '--arg2=val2']
]);
Process constructors for cleaner code.proc_open edge cases.Why Migrate?:
shell_exec/exec hacks with a battle-tested, actively maintained solution.Process in Artisan commands for CLI-driven tasks.RunProcessMessage.Migration Steps:
composer.json:
"require": {
"symfony/process": "^8.1"
}
Process:
// Before (custom)
exec('docker build --build-arg KEY=val1,val2 .');
// After (Symfony Process)
$process = new Process(['docker', 'build'], [
'BUILD_ARGS' => ['--build-arg', 'KEY=val1,val2']
]);
$process->run();
$process = new Process(
command: ['docker', 'build'],
env: ['KEY' => ['val1', 'val2']],
timeout: 3600,
);
Risks & Mitigations:
Let’s adopt this to reduce technical debt, enable modern PHP, and simplify DevOps workflows."
How can I help you explore Laravel packages today?