Run and Monitor Laravel Queue using PM2

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 .

- name: your-worker-name
script: artisan
exec_mode: fork
interpreter: php
instances: 1
- 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.

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…




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store