Laravel Horizon provides a dashboard for Laravel-powered Redis queues, which allows you to create jobs that can be processed in the background. On top of this, Horizon allows you to monitor job throughput, runtime, and job failures.
To install Horizon for your project, run
composer require laravel/horizon.
After installing Horizon, run
php artisan horizon:install to publish its assets.
The primary configuration file for Horizon is located at
It allows you to configure queue worker options for your application.
The primary Horizon option is
This consists of an array of environments that your application runs on and defines
the options for each environment and defines
Once you’re done with the configuration, you may start Horizon using the
php artisan horizon
command. This will expose a dashboard located at
You may pause the Horizon process using
php artisan horizon:pause and continue the process by using the
php artisan horizon:continue.
All that work and the Horizon dashboard is ready at
When you’re all done and ready to deploy Horizon to your application’s actual server,
you should create a process monitor that restarts Horizon (
php artisan horizon)
if it exits unexpectedly.
During the deployment process, Horizon should be terminated (
php artisan horizon:terminate)
so that Horizon is restarted by the process monitor and receives your code changes.
If you are using Ubuntu, install
sudo apt-get install supervisor.
Supervisor is a process monitor that will help us restart our
horizon process once it’s terminated.
Now, SSH into the server and run the following command:
cat > ‘/etc/supervisor/conf.d/horizon.conf’ << ‘EOF’ [program:horizon] command=php /home/cleavr/horizon.cleavr-one.com/artisan horizon directory=/home/cleavr/horizon.cleavr-one.com/current startsecs=0 autostart=true autorestart=true startretries=3 stopwaitsecs=3600 stderr_logfile=/var/log/horizon.err.log stdout_logfile=/var/log/horizon.out.log user=cleavr EOF
This will create a configuration file
It will start and monitor a
Configuring the supervisor yourself and terminating the
horizon process before every deployment
may sound like too much work... Which, it is!
In the next part of this blog, we’ll showcase a solution that takes care of all these processes and enables Horizon in a matter of a click. ;)
Sign up for a 5-day free trial of Cleavr Pro. No credit card required until you decide to subscribe.Sign up for free