I would definitely suggest using the queue as the response time would be immense i expect. Maybe grouping them in batches? I'm not the best person but i think queues are the way forward
sending more than 10,000 sms
hello , i'm working on project with laravel that will send sms to many contacts, the contacts more than 10,000 , and i am using nexmo or twilio, they have good api ,but my question is what the best salution to do that ::
is to insert 10,000 job in the queue, esh job will send 1 sms ??
$contact = Contacts::all();
foreach ($contacts as $contact) {
$this->dispatch(new SendSMS($contact));
}
or make it run without queue
$contact = Contacts::all();
foreach ($contacts as $contact) {
$contact->sendSMS();
}
what is the best saluotion ? if there another one ?
@Sulieman Use the queue. You do not want to be trying to send 10,000 SMS message via a HTTP API in a single page load. If one fails and kills the loop, or the page load times out (or a hundred other scenarios where things can go wrong), how do you know which one it was and where to pick up again?
Instead, use the queue component. It’s exactly what it’s built for. Add a job per SMS, and have a queue worker run them. The queue worker will process each SMS one at a time. If you need SMS messages to be sent quicker than that, then that’s where you would scale and have more than one worker working on your queue. The theory is: twice as many queue workers would process the queue in half the time.
Some example code:
foreach ($users as $user) {
$this->dispatch(SendSmsToUser($user, $message));
}
Your SendSmsToUser job class will need to know how to fetch an SMS number for a user. And you’ll also need to specify the $message body.
Please or to participate in this conversation.