- How do I replace a manual `exec()` call in Laravel with this package?
- Use `CommandLauncher::dispatch('php artisan command:args')` to wrap your shell command. For example, replace `exec('php artisan optimize')` with `CommandLauncher::dispatch('php artisan optimize')->run()`. This centralizes command execution and adds Laravel’s logging and error handling.
- Can I run commands asynchronously in the background?
- Yes, pair the package with Laravel Queues. Dispatch a job that uses `CommandLauncher` and implements `ShouldQueue`. This is ideal for long-running tasks like media processing or database migrations to avoid blocking HTTP requests.
- Does this package support chaining commands (e.g., run A, then B if A succeeds)?
- Absolutely. Use method chaining like `CommandLauncher::dispatch('command1')->then('command2')->run()`. You can also add custom logic with `onSuccess()` or `onFailure()` callbacks for error handling or notifications.
- What Laravel versions and PHP versions are officially supported?
- The package is tested with Laravel 8+ and requires PHP 8.0+. For older Laravel versions (7.x), check the package’s GitHub for compatibility notes or fork it for custom adjustments. Always test thoroughly in your environment.
- How do I handle command failures or timeouts gracefully?
- Set timeouts with `->timeout(seconds)` and handle failures via `->onFailure()`. For retries, combine with Laravel’s queue retries or implement custom logic. Log errors using Laravel’s logging channels for observability in production.
- Is this package safe against shell injection attacks?
- Yes, but only if you use it correctly. Always pass pre-validated commands (e.g., hardcoded Artisan commands or whitelisted CLI tools). Avoid dynamic command strings built from user input. For extra safety, pair it with Laravel’s `Process` facade for stricter input sanitization.
- Can I use this to trigger external CLI tools like `ffmpeg` or `composer`?
- Yes, the package is designed for this exact use case. For example, `CommandLauncher::dispatch('ffmpeg -i input.mp4 output.mp4')->run()` will execute the command while keeping your code clean. Ensure the CLI tool is installed in your runtime environment.
- How does this compare to Laravel’s built-in `Process` facade?
- The `Process` facade is simpler but synchronous-only, while `digitalnoise/command-launcher` adds Laravel-specific features like queue integration, method chaining, and better error handling. Use `Process` for quick, one-off commands and this package for reusable, scalable workflows.
- Will this work in a Dockerized or serverless environment?
- Yes, but ensure your Docker containers or serverless functions have the required CLI tools installed (e.g., `ffmpeg`, `composer`). For serverless, use short-lived containers or pre-installed dependencies. Test thoroughly in your deployment environment to avoid missing dependencies.
- How do I log command outputs or debug issues in production?
- Leverage Laravel’s logging channels by configuring the package to log command outputs. For debugging, use `->onFailure()` to log exit codes or stderr. You can also extend the package to emit events or notifications (e.g., Slack alerts) for critical failures.