Horizon Configuration
Horizon provides a beautiful dashboard and code-driven configuration for your System. Horizon allows you to easily monitor your queue system such as job throughput, runtime, and job failures. All of your worker configuration is stored in a single, simple configuration file.
Deploying Horizon
If you are deploying Horizon to a live server, you should configure a process monitor to monitor the php artisan horizon
command and restart it if it quits unexpectedly. When deploying fresh code to your server, you will need to instruct the master Horizon process to terminate so it can be restarted by your process monitor and receive your code changes.
If you are not install supervisor yet then run sudo apt install -y supervisor
to install supervisor. Run the following command to check supervisor is installed.
supervisord --version
Configuring Horizon
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 supervisor how your processes should be monitored. For example, let's create a horizon.conf
file that starts and monitors a horizon
process:
[program:horizon]
process_name=%(program_name)s
command=php /var/www/html/project_directory/artisan horizon
autostart=true
autorestart=true
user=root
redirect_stderr=true
stdout_logfile=/var/log/horizon.log
stopwaitsecs=3600
Replace project_directory
to your project directory name. If your server does not have root
user, then change the user
as well. Make sure /var/log/horizon.log
the file is created and has write permission
Update Queue Connection
Update your queue connection to redis in your .env file:
QUEUE_CONNECTION=redis
After updating .env
file. Clear your config file by following command:
php artisan clear:all
Starting Supervisor
Once the configuration file has been created, you may update the Supervisor configuration and start the processes using the following commands:
supervisorctl reread
supervisorctl update
supervisorctl start horizon
You need to run the following command to check if your supervisor is running successfully.
supervisorctl status