Reputation: 43
We have set up GCM client and functionality of sending Push Notification using PHP script also works fine. Now next task is Android APP has thousands of registered devices.
What is proper way to send Push Notifications to all of these devices ?
I am using PHP web server (HTTP). I hope my question is clear enough.
Working Script in use for sending PUSH Notifications
<?php
// please enter the api_key you received from google console
$api_key = "proper-api-key";
$name = $_POST['name'];
$deal = $_POST['deal'];
$valid = $_POST['valid'];
$address = $_POST['address'];
// please enter the registration id of the device on which you want to send the message
$registrationIDs= array("Few registrationIDs");
$message = array("name" => $name, "deal" => $deal, "valid" => $valid, "address" => $address);
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array( "message" => $message ),
);
$headers = array(
'Authorization: key=' . $api_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, json_encode( $fields ) );
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>
Upvotes: 1
Views: 2834
Reputation: 43
I got a link to official document. http://developer.android.com/training/cloudsync/gcm.html#multicast
Here it clearly specifies the way to handle above said issue. So this question is answered now ! :)
Send Multicast Messages Efficiently One of the most useful features in GCM is support for up to 1,000 recipients for a single message. This capability makes it much easier to send out important messages to your entire user base. For instance, let's say you had a message that needed to be sent to 1,000,000 of your users, and your server could handle sending out about 500 messages per second. If you send each message with only a single recipient, it would take 1,000,000/500 = 2,000 seconds, or around half an hour. However, attaching 1,000 recipients to each message, the total time required to send a message out to 1,000,000 recipients becomes (1,000,000/1,000) / 500 = 2 seconds. This is not only useful, but important for timely data, such as natural disaster alerts or sports scores, where a 30 minute interval might render the information useless
Upvotes: 3