I have an app which aims to send notifications to IOS/Android users, our target users in future 500K users, taking into consideration that we're using FCM technology on Firebase to send to both apps, and also have a look to the PHP code which is responsible to send [login to view URL] need to know if the approach we're using is the right approach in terms of real time notification with no delay. I heard there's a maximum connection of notifications (i.e 1000 notification per once).
What we are expecting is that someone who worked in similar projects of sending thousands of messages at once and receiving in less than 5 sec to all users. I heard there is something else called Topic, if we have something wrong with backend code or something we need to know.
if(count($androidFCMs)){
//Send to android users:
$fields = array (
'registration_ids' => $androidFCMs,
'data' => $content
);
$fields = json_encode ( $fields );
$headers = array (
'Authorization: '.$server_key,
'Content-Type: application/json'
);
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_POST, true );
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $fields );
$result = curl_exec ( $ch );
if($result === false)
{
//Log error to a log file
$current = file_get_contents($file);
$current .= "\t" . 'CALL API ERROR, FOR ANDROID REQUEST: \n' .curl_error($ch) . "\n";
$msg = str_replace('{ANDROID_TOTAL}', 0, $msg);
$msg = str_replace('{ANDROID_SENT}', 0, $msg);
$msg = str_replace('{ANDROID_FAILED}', 0, $msg);
$msg = str_replace('{ANDROID_PER}', '0%' , $msg);
$current = file_get_contents($file);
$current .= "\n\t" . 'Android API RESPONSE: ' .' NO USERS FOUND. NO API CALLED TO GET A RESPONE!' . "\n-\t-\t-\t-\n";
file_put_contents($file, $current);
}
curl_close ( $ch );
}
if(count($iosFCMs)){
//Send to ios users:
$iosData = [
'activityId' => $content->activityId,
'type' => $content->type,
];
$iosNotification = [
'title' => $content->headline,
'body' => $content->body,
];
$fields = array (
'registration_ids' => $iosFCMs,
'priority' => 'high',
'data' =>$iosData,
'notification' => $iosNotification
);
$fields = json_encode ( $fields );
$headers = array (
'Authorization: '.$server_key,
'Content-Type: application/json'
);
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_POST, true );
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $fields );
$result = curl_exec ( $ch );
if($result === false)
{
$current = file_get_contents($file);
$current .= "\t" . 'CALL API ERROR, FOR IOS REQUEST: \n' .curl_error($ch) . "\n";
$msg = str_replace('{IOS_TOTAL}', 0, $msg);
$msg = str_replace('{IOS_SENT}', 0, $msg);
$msg = str_replace('{IOS_FAILED}', 0, $msg);
$msg = str_replace('{IOS_PER}', '0%' , $msg);
$current = file_get_contents($file);
$current .= "\t" . 'iOS API RESPONSE: ' .' NO USERS FOUND. NO API CALLED TO GET A RESPONE!' . "\n-\t-\t-\t-\n";
file_put_contents($file, $current);
}
curl_close ( $ch );
}