How to send push notification in android using php? [closed]

Android Push Notification requires you to have GCM Keys and Project ID which needs to be registered on Google Developer console.

I am assuming you are able to get your users registration IDs and stored in a table.

To send Android Push Notification create a function somewhere in your functions file

function AndroidPushNotification($registration_ids, $message) {

$url="https://android.googleapis.com/gcm/send";
$fields = array(
    'registration_ids' => $registration_ids,
    'data' => $message,
);

define('GOOGLE_API_KEY', 'YOUR-API-KEYS');

$headers = array(
    'Authorization:key=' . GOOGLE_API_KEY,
    'Content-Type: application/json'
);
echo json_encode($fields);
$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_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));

$result = curl_exec($ch);
if($result === false)
    die('Curl failed ' . curl_error());

curl_close($ch);
return $result;

}

Fetch all registration IDS from your database and call this function. Break registration IDs into group of 999. Sometimes, if your array has more than 1000 registration IDs, the notifications aren’t delivered.

If you subscribers list if very big, you can also look for multi-curl option which will be faster.