ScanSkill
Sign up for daily dose of tech articles at your inbox.
Loading

How To Run And Monitor Laravel Queue Using PM2

How To Run And Monitor Laravel Queue Using PM2
How To Run And Monitor Laravel Queue Using PM2

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, I am going the show how pm2 can be used to run and monitor the Laravel queue.

Prerequisite

  1. Install Node/NPM
    Learn how to install Node js on ubuntu easy way. Or install using NVM

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.yml

Thank You.

Sign up for daily dose of tech articles at your inbox.
Loading