Md Hasibur Rahaman
Md Hasibur Rahaman

Reputation: 1061

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

Upvotes: 0

Views: 4428

Answers (2)

Aleksandar
Aleksandar

Reputation: 48

No, you don't need to schedule this process

as long as queue:work process is running he will look at your "jobs" table and run task by task

what you need is something to make sure that the process doesn't end when you close the console, as user8555937 and Webinion said you need supervisor and its configuration file, once you run it it will run in the background and you can forget about it

Upvotes: 0

user8555937
user8555937

Reputation: 2377

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

Upvotes: 3

Related Questions