【问题标题】:Why did I get a timed out error after queuing up 7k jobs?为什么排队 7k 作业后出现超时错误?
【发布时间】:2021-03-07 22:03:15
【问题描述】:

我正在使用 Laravel 和 SES 发送大约 7k 封电子邮件。因为我有每秒 10 封电子邮件的限制,所以当 Laravel 一次分批发送 10 封电子邮件时,我需要延迟。

控制器

public function queue(){

$invites = Subscriber::all();
$send_at = now();

foreach ($invites as $i => $invite){

    if($i % 10 == 0){
        $send_at = $send_at->addSeconds(1);   
    }

    SendEmailJob::dispatch($invite)->delay($send_at);
}

dd('sent!');
}

还有工作

public function handle()
{   
    Mail::to($this->user->email)->send(new InviteMail($this->user));

}

这给了我一个超时错误,但奇怪的是它将所有 7k 电子邮件排队并发送。我只是好奇为什么会出现错误。

【问题讨论】:

    标签: laravel laravel-7 laravel-jobs laravel-vapor


    【解决方案1】:

    将此函数放在控制器函数的开头

    set_time_limit() //In seconds
    

    它会增加最大执行时间。

    【讨论】:

    • 但将所有作业排队只需 1 秒。我不必等待它发送所有电子邮件。
    • 可能你没有正确排队。看这个对你有帮助Queue Mails Laravel
    【解决方案2】:

    检查您的 php.ini 文件中的 max_execution_time 值或在您的 function queue() 中使用 set_time_limit(700);

    700 来自 7000 个邀请 /10 = 700 段

    max_execution_time 默认为 300 段

    【讨论】:

    • 但将所有作业排队只需 1 秒。我不必等待它发送所有电子邮件。对吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-25
    • 1970-01-01
    相关资源
    最近更新 更多