简体   繁体   中英

Most efficient way of implementing an email queue in Laravel

I want to implement a queue for sending out emails in Laravel. I have the queue working fine, but am worried about efficiency. These are my settings:

I have created the jobs table and set up the .env file, to use the queues with my local database.

I have set up this crontab on the server:

* * * * * php /var/www/imagine.dev/artisan schedule:run >> /dev/null 2>&1

And have set up a schedule in app\\Conosle\\Kernel.php, so I dont have to manually enter the 'queue:listen' every time through console.

$schedule->command('queue:listen');

Now to my question. I would like to know if this is efficient? I am worried about having the queue:listen running all the time in the background consuming cpu and memory.

I have been trying to only run the queue:listen once every 5 minutes, and then put it to sleep with

$schedule->command('queue:listen --sleep 300');

but again, am not sure if this is the best approach.

Another thing I tried is using 'queue:work', but this only processes one queue at a time.

Ideally, I would like a way, to process all the queues every 5 minutes, avoiding a constant use of memory and cpu.

What is the best approach?

Not sure which version of Laravel you're using, but I suspect it's 5.2 or earlier. You do not need to run this every minute, it continues to run until it's manually stopped.

From Laravel 5.2 documentation:

Note that once this task has started, it will continue to run until it is manually stopped. You may use a process monitor such as Supervisor to ensure that the queue listener does not stop running.

So maybe you want to look into Supervisor

Also, if this is helpful at all, you can chain onto $schedule, ->everyFiveMinutes(). There are several other methods available as well. Laravel Scheduling

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM