Setting Up Queue Worker in Laravel to a server eg Digital Ocean

Photo by Kevin Ku on Unsplash

To have queue worker on our server we need a service which can allow to run queue:work all the time. So we need a supervisor

Supervisor is a process monitor for the Linux Operating System, and it will automatically restart queue:work process if it fails

Installation

To install Supervisor on Ubuntu, you may use the following command:

sudo apt-get install supervisor

After installing Supervisor on our server we need to go to conf.d directory

cd /etc/supervisor/conf.d

Create a new configuration file

create a new file eg queue-worker.conf to handle all our instructions

#create new file via vim/nano

sudo nano /etc/supervisor/conf.d/queue-worker.conf

#setup the command

[program:queue-worker]

process_name=%(program_name)s_%(process_num)02d

command=php /var/www/html/artisan queue:work

autostart=true

autorestart=true

user=root

numprocs=8

redirect_stderr=true

stdout_logfile=/var/www/html/worker.log

the command specifies where your project is located in your server

Starting the supervisor service

Everything is setup now, but we have not told our supervisor to read this new file. We have to start the reading process.

sudo supervisorctl reread

the supervisor now knows there is a new file but we have to restart the service also

sudo supervisorctl update

then the we need to instruct the supervisor to restart

sudo supervisorctl reload

or

sudo service supervisor restart

Thats It!, you can read more about creating jobs and queues on laravel docs

code is here

--

--

Felix Ivance Runye

I am a Software Engineer, and an Adventurer, who is passionate about cycling, biking, and reading. Always on the lookout for new challenges.