In most cases you’d use supervisor.d or some other monitoring daemon to look after queue worker process in Laravel applications, In this post, we going the show how pm2 can be used to run and monitor the Laravel queue.
Step 1: Install PM2
To download and install the latest version of pm2 run the following command on terminal, assuming that node is installed. If the node is not installed, please refer to this official doc to get it installed on your local machine.
sudo npm i -g pm2
Step 2: Configure PM2 file for Laravel queue
Create laravel-queue-worker.yml file on the root of the Laravel project and put the following code.
apps:
- name: laravel-queue-worker
script: artisan
exec_mode: fork
interpreter: php
instances: 1
args:
- queue:work
- --tries=5
- --sleep=1
Step 3: Run and Monitor queue from PM2
From the root folder of the Laravel application, run the following command.
pm2 start laravel-queue-worker.yml
which will show following info in the terminal.
Step 4: View log and monitor the queue process.
To view the logs in pm2 simply enter the following command.pm2 logs laravel-queue-worker
Thank You.