Interview frequency: …
Short answer
Create a configuration file in /etc/supervisor/conf.d that specifies the queue:work command, process count, automatic startup, and immediate restart after a crash.
Explanation
Do not run php artisan queue:work directly in a terminal, because it stops when the SSH session closes. Supervisor manages processes as system daemons: it monitors workers continuously, immediately restarts any worker that exits because of a timeout or memory error, and automatically restarts them when the server reboots.
Code example
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/app/artisan queue:work redis --sleep=3 --tries=3
autostart=true
autorestart=true
user=www-data
numprocs=8
redirect_stderr=true
stdout_logfile=/var/www/app/storage/logs/worker.logCommon mistakes
- Running Supervisor workers as root instead of the web server user www-data.
Follow-up questions
- What is the main difference between php artisan queue:work and queue:listen?
- How do you design multiple Laravel queues with different priorities (High, Default, Low)?