Laravel - How to use queues

Use queue in Laravel

Laravel - How to use queues
Photo by Hal Gatewood / Unsplash

Notes after reading the tutorial and the reference

Main points

  • Queues driver: the details handling how to queue
  • Job Class: defined the actions to be execute

Configurations

The configuration file of queues is config/queue.php, the default queues driver and the configuration for each driver available, like Beanstalkd, Amazon SQS, Redis

Step 1 - A Job

php artisan make:job JOBNAME

Step 2 - The handle() method

Any specific task that should be performed by this job should be put in the handle() method

Step 3 - Dispatching the job to the queue

$this->dispatch(new JOBNAME());

Useful information:

Additional parameters

It can be done by editing the constructor of JOB then invoke as follow

$this->dispatch(new JOBNAME($parameter));

Listing to queues

php artisan queue:listen database