Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nodenacci's avatar

How to execute a PHP code function concurrently for different processes. Sms scenario

I have been working on a Bulk Sms product and off-late we have been having challenges on the number of sms sent at a time. We have tried several ways to optimize both we have not yet reached a good solution.

Our provider provides provides an endpoint that sends a single SMS at once(we are request for multiple). We have a function that sends an SMS to that endpoint. Now lets say I have a user who has 10K contacts in a group, and we want to send SMS to that endpoint with the best time as possible.

Is there anyway i can make my code execute the function to concurrently while generating the SMS to my db table?

For example, lets assume the send sms function as sendSms($phone, $message)

Then lets generate the SMS from a group of 10K contacts:

foreach($group->contacts as $contact) {
 //from a controller
 $this->dispatch(new SendSmsJob($contact->phone, $contact->message))->onQueue('high');
}

Clearly the SMS will be created and queued lets say redis, but they are sent sequentially. Is it possible to do a concurrency? Is AWS lambda a solution? or Lavavel Vapor?

0 likes
1 reply
aurawindsurfing's avatar

@mulugu I think the issue when you manage to do this would be with your SMS provider. You should ask them what is API threshold as you will not be able to send more then they allow per minute anyway. It all depends on their setup.

The way I tried to solve this (I use physical devices) was to have 5-6 of them. Sending 10k takes some time but it is ok. Even something like Nexmo might take a while to send it all depends on infrastructure.

1 like

Please or to participate in this conversation.