Replace queue worker with Horizon in Docker
45sShows a simple one-line change to switch from queue worker to Horizon, saving developers time.
▶ Play ClipThis tutorial demonstrates how to set up Laravel Horizon in a Docker environment using a pre-made template. The process involves modifying the Docker Compose file, installing the PCNTL extension, installing Horizon via Composer, and configuring it to monitor queues. The video also shows how to create a test job and verify that Horizon is working correctly through its dashboard.
The presenter introduces a Docker template with Laravel, queue worker, Nginx, database, and Redis, which simplifies the Horizon setup.
Rename the queue worker service to 'horizon' and change the start command from 'queue:work' to 'horizon'.
Add the PCNTL PHP extension to the Dockerfile, as it is required by Horizon.
Run 'composer require laravel/horizon' inside the backend directory, then 'php artisan horizon:install' to publish configuration and assets.
The config/horizon.php file allows setting supervisors, processes, memory limits, queue balancing strategies, etc.
Create a ProcessPodcast job that logs output, and add a route to dispatch the job.
Ensure .env has correct Redis host, password, and port (use service name for Docker, localhost for local).
Run 'docker compose up --build -d' to build and start containers.
Visit /horizon to see the dashboard showing active processes, metrics, batches, pending and completed jobs.
Hit the route multiple times to dispatch jobs; verify they appear as completed in the dashboard.
Setting up Laravel Horizon in Docker is straightforward: modify the Docker Compose file, install PCNTL and Horizon, configure the service, and use the dashboard to monitor queues. The presenter encourages viewers to like the video to help others avoid overpriced templates.
"The title accurately describes the video content; it's a straightforward setup guide for Laravel Horizon."
What PHP extension is required by Laravel Horizon?
PCNTL
0:47
What command installs Laravel Horizon via Composer?
composer require laravel/horizon
1:10
What command publishes Horizon's configuration and assets?
php artisan horizon:install
1:25
In the Docker Compose file, what service name should replace the queue worker?
horizon
0:33
What is the purpose of the config/horizon.php file?
It allows configuring supervisors, number of processes, memory limits, queue balancing strategies, etc.
1:35
When running Horizon in a Docker environment, what should the Redis host be set to in .env?
The service name of the Redis container (e.g., 'redis').
2:42
What URL path provides access to the Horizon dashboard?
/horizon
3:08
Minimal Docker Compose Change
Only two changes are needed: rename the service and change the command, showing how simple the setup is.
0:30Composer Installation
Horizon is installed via Composer, a standard PHP package manager, making it accessible to Laravel developers.
1:02Configuration File
The config/horizon.php file centralizes queue management settings, giving developers fine-grained control.
1:32Dashboard Overview
The Horizon dashboard provides real-time metrics, job history, and failure tracking, which is valuable for monitoring production queues.
3:00Testing the Queue
Dispatching multiple jobs and seeing them appear in the dashboard confirms that Horizon is working correctly.
3:18[00:00] right so I'm going to show you how to
[00:01] use Horizon today we're going to deploy
[00:03] it in our doer environment and it's
[00:04] going to be really simple I'm using this
[00:06] template here and it's my own template
[00:09] that I made from one of the previous
[00:10] videos I'll put a link in the
[00:11] description you can just clone it and
[00:13] continue to work from there the template
[00:14] already has the laravel app it has a q
[00:17] worker it has ngx database and Redd is
[00:20] ready so it's going to be fairly simple
[00:22] to use I recommend that you start from
[00:24] this template but if you have your own
[00:26] Docker compose file you can just use
[00:28] that so let's get started here the first
[00:30] thing that we have to replace here is
[00:31] the Q worker so instead of naming it Q
[00:33] worker we have to name this service
[00:35] Horizon and we're going to change the
[00:36] start command from Q work to Horizon so
[00:39] this is the only thing required to be
[00:41] changed in the dock compose yl file we
[00:43] have to run Horizon with this command
[00:46] next thing that we have to do is go to
[00:47] our Docker file and we have to install
[00:50] pcnl as our dependency so we're going to
[00:52] be adding pcnl this is used by Horizon
[00:55] and that's why we're installing it now
[00:57] we're done with the docker file and
[01:00] we're done with Docker composed. yaml we
[01:02] have to install Horizon so you're going
[01:03] to go to LL you're going to go to the
[01:05] latest version and you're going to
[01:07] install Horizon with composer so I'm
[01:10] going to open my terminal I'm going to
[01:12] CD into the backend directory so you
[01:15] should be careful to not install it here
[01:17] in the root you should install it in the
[01:19] back end and you copy this command we
[01:21] install Horizon and then once this is
[01:23] install we just have to run PHP artison
[01:25] Horizon install the scaffolding is done
[01:29] and you should see new files in your
[01:32] project here we have the horizon. PHP
[01:35] file and this gives you the config for
[01:37] Horizon you should read this
[01:38] documentation up I'm not going to be
[01:40] doing a tutorial on this but essentially
[01:42] you have the supervisors and you can say
[01:44] how many processes there are the memory
[01:46] how many jobs cues and so on balancing
[01:49] in these strategies and so on so you
[01:52] have this file here and we're mostly set
[01:54] up so let's add a test job here and I'm
[01:56] going to add a process click job and
[02:00] this is going to be a really simple job
[02:01] we're just going to go to the process
[02:03] click here and we're going to add a log
[02:06] so we want to see the output and we want
[02:08] to see if this works and we're going to
[02:09] import this from the support log here
[02:13] and there you go so we have this process
[02:14] click job and now we want to go to our
[02:17] routes web and let's add a process click
[02:21] job so for example we can go to our a
[02:24] URL and it's going to be adding a job to
[02:27] the queue and returning a response Json
[02:30] so once we set everything up here we
[02:32] check our EnV our EnV should have PHP
[02:35] redus the redus host the redus password
[02:38] and the red is Port again when you're
[02:40] running this from a Docker environment
[02:42] you're going to be adding the service
[02:44] name but when you're running this
[02:46] locally you should be adding this local
[02:48] host address so if we have everything
[02:50] set up here we can just say Docker
[02:53] compose up build detach and wait for the
[02:56] containers to finish building so now
[02:58] that the containers have been built
[03:00] let's go to our Local Host here so I'm
[03:03] going to go to Local Host we have the
[03:06] laravel let's go to
[03:08] Horizon and we have the Horizon
[03:10] dashboard that's it here you go total
[03:12] process is one it's active we have
[03:14] monitoring metrics batches pending jobs
[03:17] completed jobs and let's just test it
[03:18] out so we have the click route so if we
[03:23] go here we returned true so it should
[03:25] run two jobs right now so if I reload
[03:28] there you go total processes Jobs pass
[03:30] to so if I go to completed jobs you see
[03:33] process click job Q default it gives you
[03:36] the data and let's just let's just run
[03:38] as many jobs as I can so I'm going to go
[03:40] here and I'm I'm going to press controlr
[03:42] here to reload as many times as I can
[03:45] and if I now go back to Horizon go to
[03:48] the dashboard you see jav's passed hour
[03:51] 35 everything's working status is active
[03:53] there if there are any fail jobs it will
[03:55] show you here you have batches metrics
[03:58] and you have in metrics here I love this
[04:00] that it shows you which queue you can
[04:03] select by which queue the jobs have been
[04:05] done and the actual job so you can
[04:07] process click and you can see the data
[04:09] of course you don't have the throughput
[04:10] and runtime because I started this like
[04:11] two minutes ago but the more data you
[04:13] have you'll have metrics here and this
[04:15] is how you can host Horizon it's very
[04:17] simple please leave a like so that other
[04:19] people see this so that they don't get
[04:21] scammed for paying templates that are
[04:24] $100 please like this so people can see
[04:26] it and I think this is beautiful Horizon
[04:29] is is a really powerful tool and you
[04:31] should use it use it in many many
[04:33] projects
⚡ Saved you time reading this? Transcribe any YouTube video for free — no signup needed.