I received an email from Google informing me that the following service is being decommissioned:
"Including multiple send requests in a single HTTP request to FCM known as Batch Send."
The recommended approach is to:
"Send messages via the HTTP v1 API, which has been optimized for fanout performance."
On this page:
https://firebase.google.com/support/faq#fcm-23-deprecation
it is mentioned that:
https://fcm.googleapis.com/batch
"Requests to the endpoint will start failing after 6/21/2024."
The recommended action is to:
"Migrate to the standard HTTP v1 API send method, which supports HTTP/2 for multiplexing."
Now, I have a question regarding this matter.
Currently, I am sending FCM messages using PHP and cURL via fcm.googleapis.com/batch. Since this will no longer work next year, I have already discontinued this method and now I have put the message sending process in a foreach (while) loop. This means that if, for example, I send 400 FCM messages, I will trigger or contact the following URL 400 times in succession / row:
https://fcm.googleapis.com/v1/projects/my-app/messages:send
Is this the intended behavior and not a problem? My project already uses HTTP/2. I'm just wondering if this is the correct approach, as I can't imagine that it is better than sending in batches or all at once. Thank you for clarifying.
Please let me know if you need any further assistance.
Here my foreach code:
foreach ($deviceTokens as $token) {
$data = json_encode(array(
"message" => array(
"token" => $token,
"notification" => array(
"message_title" => "Test",
"message_body" => "Test",
"website_link" => "example.com",
"notification_type" => "message",
"image" => "example.com/test.jpg"
)
)
));
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://fcm.googleapis.com/v1/projects/my-app/messages:send',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $request,
CURLOPT_HTTPHEADER => array(
'Content-Type: multipart/mixed; boundary="subrequest_boundary"',
'Authorization: Bearer ' . $accessToken
),
));
$response = curl_exec($curl);
echo $response . '<br />';
curl_close($curl);
}