BR
asked on
PHP using CURL inside while loop
Dear Experts,
I connect a server using CURL to send SMS messages.
First, I select the data from my database and send it to the selected numbers.
Then I put it inside a while loop to send it to every number using CURL.
I use below code,
but I wonder which part should I use inside the while loop?
Do I have to initialize CURL for every time?
Which part should I use inside the while loop?
I connect a server using CURL to send SMS messages.
First, I select the data from my database and send it to the selected numbers.
Then I put it inside a while loop to send it to every number using CURL.
I use below code,
but I wonder which part should I use inside the while loop?
Do I have to initialize CURL for every time?
Which part should I use inside the while loop?
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "xxxxxxx",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\r\n\t\"xxxxx\"\r\n\t}\r\n}",
CURLOPT_HTTPHEADER => array(
"accept: application/json",
"authorization: ".$kullanici_sifre."",
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER