How do we configure the queue for production?
In production, you need a way to keep your queue:work processes running. A queue:work process may stop running for a variety of reasons, such as an exceeded worker timeout or the execution of the queue:restart command.
Supervisor is a process monitor commonly used in Linux environments and we will discuss how to configure it in the following documentation.
Step 1: Installing Supervisor
Supervisor is a process monitor for the Linux operating system, and will automatically restart your queue:work processes if they fail. To install Supervisor on Ubuntu, you may use the following command:
sudo apt-get install supervisor
Step 2: Configuring Supervisor
Supervisor configuration files are typically stored in the /etc/supervisor/conf.d directory. Within this directory, you may create any number of configuration files that instruct supervisors how your processes should be monitored. For example, let’s create a laravel-worker.conf file that starts and monitors queue:work processes:
[program:laravel-queue-project1]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/project1/artisan queue:work --queue=default --sleep=3 --tries=3 --max-time=3600
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=www-data
numprocs=8
redirect_stderr=true
stdout_logfile=/var/log/laravel-queue.log
This configuration file will run laravel-queue as background process and log along with other data will be saved inside /var/log/laravel-queue.log file.
Step 3: It’s time to Reload Supervisor
Once the configuration file has been created, you may update the Supervisor configuration and start the processes using the following commands:
sudo supervisorctl reread
sudo supervisorctl update
Step 4: Start laravel queue
sudo supervisorctl start laravel-queue-project1:*
It’s time to insert a new job and test it.