I have to do the following:
I have a Daemon set up that every hour, executes the nohup command (by calling exec(‘nohup sms.php ….’), and sms.php goes through a database of users and sends an sms message to each user at the same time. It does so by contacting (via curl) a third party message service.
So sms.php is structured as follows:
$sql = 'SELECT * FROM users'.
$q = execute sql query
while($r = ....)
{
// url is the url to the third party service that handles sending sms
$ch = curl_init($url);
call curl functions
$data = curl_exec();
}
Basically, I want sms.php to be able to handle sending sms messages to over 1000 users at the same time. So users should be getting the sms at the same time.
How can I improve the code to allow for:
– sending the sms at the same time to all users
– handling over 1000 users (meaning that sending the sms messages should not take a long time for each user, and apache or PHP can not block me for sending that many)
EDIT: I do not want to use external APIs. Just the curl functions. Thanks!
EDIT: Third party server provides a url that we have to access using CURL to send SMS messages.
I have no clue how the third party service work,
so probably that is no option for sending multiple SMS in a single API call.
Use the curl_multi_exec.
I don’t think concurrently fire 1000 request is possible,
but 100~200 requests should be no problem.
You can do a check at your code level,
at the same loop,
do a
$cnt++,when
$cnt=100,execute multi curl,
reset
$cnt,repeat until end of the loop.