phplaravellaravel-queuelaravel-jobs

How to process php artisan queue:listen


I am facing a serious problem in Laravel Queue system please help me to fix this issue.

Once I queue my mail by using

$mailer = Mail::to($email_to)->queue(new ContactGeneral($data));  

it stores into the database and runs this command from terminal php artisan queue:listen it works fine once I close my terminal it does not listen to my queue.

For that, I set up a scheduled in kernem.php file like that which run in every minute

protected function schedule(Schedule $schedule){
    $schedule->command('queue:listen')->everyMinute();
}

set this line in a cronjob and work fine

* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

Problem is as runs every minute run every minute it not kill the previous process and run another process in next minute it slowdown my server

Please can you let me know what is the best way to implement this

Thanks in advance


Solution

  • Best way is to use supervisor. Though if you are running the application in a shared hosting environment, you can process the queues once and then exit the process thus freeing up the memory by using the following command:

    php artisan queue:work --once
    

    Depending on how many queues you'll have, set the queue to run once every 1, 2 or 3 minutes to make sure the previous process has time to consume the queues and they won't interfere often. I think you can use the following command:

    * * * * * cd /path-to-your-project && php artisan queue:work --once