Laravel queue system with job
#code4mk #laravel
# Queue: Queue is a FIFO (first in first out). Queue task waiting to complete the previous task.
Laravel Queue: Laravel queue system increase performance of request and reduce the loading time.
Basically queue is a time-consuming task but run background on the server.
# Job
Job is a specific task for a specific queue.
# set queue connection on .env file
QUEUE_CONNECTION=database
php artisan config:cache or php artisan config:clear
# queue table generate
php artisan queue:table
# if don't have job fails table
php artisan queue:failed-table
php artisan migrate
# create a job
php artisan make:job MailSend
This command creates a MailSend job inside App/Jobs
~ handle
basically handle method calls when the queue is processed. and payload store handle methods and others properties.
# call job inside controller or others
dispatch()
use App\Jobs\MailSend;dispatch(new MailSend($data))->delay(now()->addMinutes(1));
# run queue command on your server
php artisan queue:work
# or
php artisan queue:listen