- How do I install supervisorphp/supervisor in a Laravel project?
- Run `composer require supervisorphp/supervisor` in your project directory. The package provides a PHP client for Supervisor’s XML-RPC API, so ensure Supervisor is installed and configured with XML-RPC enabled (e.g., `rpcinterface:unix:///tmp/supervisor.sock` in your Supervisor config).
- Can I use this package to restart Laravel queue workers automatically?
- Yes. The package lets you restart processes programmatically, such as queue workers. For example, you can trigger a restart via an Artisan command or Laravel event listener when a job fails or the worker becomes unresponsive.
- What Laravel versions does supervisorphp/supervisor support?
- The package is framework-agnostic but integrates seamlessly with Laravel. Test thoroughly with your Laravel version (e.g., 10.x or 11.x), as the last release was in 2022. PHP 8.0+ compatibility is likely, but verify with your setup.
- How do I configure Supervisor’s XML-RPC socket for Laravel?
- Edit your Supervisor config (e.g., `/etc/supervisor/conf.d/supervisord.conf`) to include `rpcinterface:unix:///tmp/supervisor.sock` and ensure the socket path is accessible by your Laravel process. Permissions may require adjustments (e.g., `chmod 777 /tmp/supervisor.sock`).
- Is there a way to integrate this with Laravel’s scheduler or Horizon?
- Absolutely. Use the package to dynamically manage processes tied to Laravel’s scheduler or Horizon. For example, restart a stalled queue worker after a scheduled event or when Horizon detects a failure.
- What happens if the Supervisor XML-RPC connection drops during a Laravel request?
- Implement retry logic or fallback mechanisms in your Laravel code. The package itself doesn’t handle retries, so wrap calls in a try-catch block or use Laravel’s `retry` helper for transient failures.
- Can I use this package for managing external PHP processes, not just Laravel tasks?
- Yes. The package is designed to manage any Supervisor-controlled process, including external PHP scripts or microservices. Just define the process name in your Supervisor config and use the client to control it.
- Are there alternatives to supervisorphp/supervisor for Laravel?
- You could use native Supervisor CLI commands via Symfony’s `Process` component or direct XML-RPC calls with `curl` or `file_get_contents`. However, this package abstracts complexity and provides Laravel-specific integrations like Artisan commands and service providers.
- How do I test Supervisor interactions in my Laravel application?
- Mock the Supervisor client in your tests using Laravel’s `Mockery` or PHPUnit. Verify process states (e.g., `getState()`) and actions (e.g., `restart()`) without hitting the actual Supervisor instance. Use a test socket path in your config.
- What permissions are needed for Laravel to interact with Supervisor’s socket?
- The Laravel process must have read/write access to the Supervisor socket (e.g., `/tmp/supervisor.sock`). Adjust socket permissions (e.g., `chmod 777`) or run Laravel with the same user as Supervisor (check `/etc/supervisor/supervisord.conf` for `user=` settings).