Run and Monitor Laravel Queue using PM2

Awang Trisakti
2 min readJan 23, 2022

--

Photo by Jaime Dantas on Unsplash

In production, we need to keep our artisan queue:work running. For some reason artisan queue:work process may stop running. So we need a process monitor that keep our artisan queue:work running and monitoring running queue.

Based on Laravel documentation, process monitor used to run and monitor a queue is Supervisor. In this post I will use pm2 instead of supervisor. PM2 is a daemon process manager that will help you manage and keep your application online 24/7.

Install PM2
We can install pm2 using npm with the following command :

npm install pm2 -g

Configure PM2 file for Laravel queue
Create your-worker-name.yml in your laravel project folder, you can put the file in root folder or create a new folder such as /worker .

apps:
- name: your-worker-name
script: artisan
exec_mode: fork
interpreter: php
instances: 1
args:
- queue:work
- --tries=5
- --sleep=1

Run PM2
Open a terminal from root of the Laravel project folder, and run these following command.

pm2 start your-worker-name.yml
// Or if you put pm2 file not in root folder
pm2 start worker/your-worker-name.yml

Monitoring PM2
To monitor running Laravel queue, we can use pm2 list command and here is the result.

Monitoring pm2

That’s all that I can share from this post, please feel free to leave a coment for any suggestions or questions. Thanks for read my post. See yaa…

References
1. https://laravel.com/docs/8.x/queues#supervisor-configuration
2. https://pm2.keymetrics.io/

--

--

Responses (1)