Одна вещь, которую я заметил, это то, что вы сохраняете свой результат curl в переменную $result
. Это та же самая переменная, в которой находятся результаты вашего запроса, что заменяет его значение. Это вызовет проблемы.
Дайте это попробовать.
require 'init.php';
$body = $_POST['message'];
$title = $_POST['title'];
$url = $_POST['url'];
$path_to_fcm = 'https://fcm.googleapis.com/fcm/send';
$server_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxs";
$sql="SELECT * FROM fcm_info";
$result = mysqli_query($con, $sql);
$headers = array(
'Authorization:key=' . $server_key,
'Content-Type:application/json'
);
$message = array(
'title' => $title,
'body' => $body,
'webUrl' => $url,
'vibrate' => 1,
'sound' => 1
);
while($row = mysqli_fetch_array($result)){
$fields = array(
'to' => $row[1],
'data' => $message,
'priority' =>'high'
);
$payload = json_encode($fields);
$curl_session = curl_init();
curl_setopt($curl_session, CURLOPT_URL, $path_to_fcm);
curl_setopt($curl_session, CURLOPT_POST, true);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_session, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($curl_session, CURLOPT_POSTFIELDS, $payload);
$curlResults[] = curl_exec($curl_session); //Changed the name of variable so it
//did not overwrite your query results.
mysqli_close($con);
}