Handle queues with Horizon
Back to home
On this page
Laravel Horizon provides an appealing dashboard and code-driven configuration for your Laravel powered Redis queues. Horizon allows you to monitor key metrics of your queue system, such as job throughput, runtime, and job failures.
1. Add Laravel Horizon
Note
This procedure assumes you have followed the steps on how to configure Redis and queues.
-
To add Laravel Horizon, run the following command:
Terminalcomposer require laravel/horizon && php artisan horizon:install
-
Add the
install
command to yourbuild
hook in your app configuration, so it’s run on every deploy..upsun/config.yamlapplications: myapp: [...] hooks: build: | set -eux composer --no-ansi --no-interaction install --no-progress --prefer-dist --optimize-autoloader --no-dev php artisan horizon:install
2. Create a worker to run Horizon
To run Horizon on your project, you need to add a separate worker. To do so, use the following configuration:
applications:
myapp:
[...]
workers:
horizon:
commands:
start: |
php artisan horizon
To enable the worker, push your changes to Upsun:
git add .
git commit -m "Enable Laravel Horizon"
upsun push
A new container is started automatically. It will spawn the Horizon process after the next deploy.
3. Access your Horizon dashboard
If you have restricted access to Horizon in your HorizonServiceProvider.php
,
log in to your app through the web.
Then, go to /horizon
to access your Horizon dashboard.
4. Optional: Customize Horizon
Horizon handles jobs that are populated by the queue. If you need to customize how Horizon works (queues, processes, etc.), see the official Laravel Horizon documentation.
Warning
Web and worker containers don’t share mount targets. You can’t share files between those containers using the filesystem. To share data between containers, use services.
See more information on workers.
Note that you can customize the resources of your Horizon worker container from the Upsun Console.
For more information, see how to configure resources.