I'm sending about 300 messages using an api using CURL requests with a for loop , It's working but takes the whole CPU.
Here is the code :
//Initializing CURL.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "websiteURL");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("
Content-Type: application/json",
'Authorization: Basic '. base64_encode("XXXXX:YYYYYY")
));
//Starting for Loop.
for ($i=0; $i < 300; $i++){
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"src": "'.$numbers_from[$i] ['number_from'].'","dst": "'.$messages[$i['international_format'].'", "text": "'.$current_message.'"}');
$message = curl_exec($ch);
}
//Close CURL.
curl_close();
How to reduce the CPU ? , Is there is a function for that ? , Is there is an alternative for CURL?