Update: GCM is deprecated, use FCM
How can I integrate the new Google Cloud Messaging in a PHP backend?
You can use this PHP library available on packagist:
https://github.com/CoreProc/gcm-php
After installing it you can do this:
$gcmClient = new GcmClient('your-gcm-api-key-here');
$message = new Message($gcmClient);
$message->addRegistrationId('xxxxxxxxxx');
$message->setData([
'title' => 'Sample Push Notification',
'message' => 'This is a test push notification using Google Cloud Messaging'
]);
try {
$response = $message->send();
// The send() method returns a Response object
print_r($response);
} catch (Exception $exception) {
echo 'uh-oh: ' . $exception->getMessage();
}