简体   繁体   English

在Laravel中实现电子邮件队列的最有效方法

[英]Most efficient way of implementing an email queue in Laravel

I want to implement a queue for sending out emails in Laravel. 我想在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. 我已经创建了作业表并设置了.env文件,以便将队列与本地数据库一起使用。

I have set up this crontab on the server: 我已经在服务器上设置了此crontab:

* * * * * 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. 并且已经在app \\ Conosle \\ Kernel.php中设置了时间表,因此我不必每次通过控制台手动输入“ queue:listen”。

$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. 我担心队列:监听在后台运行的所有时间,消耗CPU和内存。

I have been trying to only run the queue:listen once every 5 minutes, and then put it to sleep with 我一直试图只运行队列:每5分钟监听一次,然后与

$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. 我尝试过的另一件事是使用'queue:work',但这一次只能处理一个队列。

Ideally, I would like a way, to process all the queues every 5 minutes, avoiding a constant use of memory and cpu. 理想情况下,我想要一种方法,每5分钟处理一次所有队列,避免不断使用内存和cpu。

What is the best approach? 最好的方法是什么?

Not sure which version of Laravel you're using, but I suspect it's 5.2 or earlier. 不知道您使用的是哪个Laravel版本,但我怀疑它是5.2或更早版本。 You do not need to run this every minute, it continues to run until it's manually stopped. 您不需要每分钟运行一次,它会一直运行直到手动停止。

From Laravel 5.2 documentation: 从Laravel 5.2文档中:

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. 您可以使用诸如Supervisor之类的进程监视器来确保队列侦听器不会停止运行。

So maybe you want to look into Supervisor 所以也许您想研究主管

Also, if this is helpful at all, you can chain onto $schedule, ->everyFiveMinutes(). 另外,如果这完全有帮助,则可以链接到$ schedule,即-> everyFiveMinutes()。 There are several other methods available as well. 还有其他几种可用的方法。 Laravel Scheduling Laravel调度

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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