0

I am currently looping through an array of numbers in PHP and sending an API request to send a message to those numbers. It works perfectly, except I am expecting the array to eventually get to over 1000 numbers and the API has a 1 call per second limit, which means it will take over 15 minutes to deliver the calls. I was told by the vendor (Telnyx) that I could make an async function that would send multiple requests at once. I searched for a solution but most of them involved server modifications, etc. Any ideas would be appreciated. Here is my loop:

$sql = "SELECT userphone from $table_name WHERE list='$received_list'";
$result = mysqli_query($con,$sql);
if($countrows = mysqli_num_rows($result) >= 1){ 
    while ($row = mysqli_fetch_array($result)){
        $propernum="+1".$row['userphone'];
        \Telnyx\Message::Create([
        "messaging_profile_id" => $profile, // Your Telnyx numbe// Your Telnyx number
        "to" => $propernum,
        "text" => $sendmessage
        ]);
        $jsent=$jsent+1;
    }
    exit;
}
  • If the API you are using has a 1 call per second limit, then how is calling it asyncronously going to help? – RiggsFolly Jan 05 '20 at 17:08
  • I was told by the vendor to use an async function so we can “execute multiple requests at a time instead of a single request”. I have no experience with this so I am assuming they know what they are talking about. I am mostly concerned about the script hanging the page when the end user submits the form that starts the loop. – Jim Armstrong Jan 06 '20 at 04:31
  • Telnyx Messaging Engineer here: by default, the limit to *send* is 1 message/second (for an increase, contact support), but *queuing* (i.e. our API call rate) can be done at about 100 messages/second. I'm not familiar with PHP, so I can't answer this question, unfortunately. Generally, making requests in some non-blocking manner (threading, processes, etc.) would allow you to make more requests/second, maybe like this?: https://stackoverflow.com/questions/9308779/php-parallel-curl-requests – Nick T Jan 30 '20 at 21:40

0 Answers0