Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Laravel Horizon as a background service

My question is what is the best and simple way to run the Laravel Horizon based job workers?

My Tech Stack

  • Laravel 5.5
  • Horizon
  • Redis Queues
  • Centos

I have gone through the document https://laravel.com/docs/5.5/horizon

How to setup following supervisor as mentioned on the link above
Supervisor Configuration

[program:horizon]
process_name=%(program_name)s
command=php /home/forge/app.com/artisan horizon
autostart=true
autorestart=true
user=forge
redirect_stderr=true
stdout_logfile=/home/forge/app.com/horizon.log

Note: I have my own custom build server with php 7.1 and I later installed Horizon to run my Jobs and maintain the queues.

Any suggestion regarding how to run the Workers or where should I configure above Supervisor Configuration?

like image 373
BetaDev Avatar asked Dec 20 '17 17:12

BetaDev


People also ask

Is Laravel job asynchronous?

The generated class will implement the Illuminate\Contracts\Queue\ShouldQueue interface, indicating to Laravel that the job should be pushed onto the queue to run asynchronously.

Is Laravel horizon free?

In addition to a brand-new, code-driven configuration system, Horizon is a truly beautiful dashboard UI, and it's totally open source and free for entire Laravel community. We're launching the beta tomorrow. I hope you love it.


1 Answers

Make sure you have supervisor installed:

For debian/ubuntu:

apt install supervisor

centos:

easy_install supervisor

or

yum install supervisor

You can also do:

systemctl enable supervisord

To make sure supervisor runs at startup


Now create a new file in /etc/supervisor/conf.d/ named horizon.conf and add the above configuration.

Now do:

sudo supervisorctl reread

To reread the configs

sudo supervisorctl update

To reload the configs and restart the process

sudo supervisorctl start all

or

sudo supervisorctl start horizon

To start horizon

like image 78
Robert Avatar answered Sep 20 '22 16:09

Robert