Why did I get a timed out error after queuing up 7k jobs?

301 views Asked by At

I'm sending around 7k emails using Laravel and SES. Because I have a limit of 10 emails per second I need to delay when Laravel is sending all the emails in batches of 10 at a time.

Controller

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!');
}

And the Job

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

}

This gave me a timed out error but weirdly it queued all 7k emails and sent them. I'm just curious why I got the error.

2

There are 2 answers

2
Mudit Gulgulia On

Put this function at the starting of your controller function

set_time_limit() //In seconds

It will increase the max execution time .

1
Lsickle On

check the max_execution_time value on your php.ini file or use set_time_limit(700); into your function queue()

700 come from 7000 invites /10 = 700 seg

max_execution_time default is 300 seg