0

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.

Victor
  • 133
  • 1
  • 6

2 Answers2

0

Put this function at the starting of your controller function

set_time_limit() //In seconds

It will increase the max execution time .

Mudit Gulgulia
  • 1,131
  • 7
  • 21
  • But it should take just 1 second to queue all the jobs. I shouldn't have to wait for it to send all the emails. – Victor Nov 25 '20 at 03:50
  • Maybe you are not queuing correctly. Watch this it will help you [Queue Mails Laravel](https://www.youtube.com/watch?v=lGOACudnLWE) – Mudit Gulgulia Nov 25 '20 at 04:31
0

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

Lsickle
  • 1
  • 3
  • But it should take just 1 second to queue all the jobs. I shouldn't have to wait for it to send all the emails. Right? – Victor Nov 25 '20 at 03:52