php-gcm/php-gcm

A PHP library for sending GCM messages

Installs: 7 955

Dependents: 1

Stars: 82

Watchers: 10

Forks: 20

Open Issues: 4

Language: PHP

1.1.1 2015-05-06 13:25 UTC

README

Why

Google Cloud Messaging for Android is great, but Google has only released a Java server side implementation. To use it with PHP we have to resort to writing custom functions or classes and dealing with HTTP, curl and headers. No More! This library is a loose port of Google's com.google.android.gcm.server Java library and makes GCM very easy and powerful in PHP.

Install

Composer is the easiest way to manage dependencies in your project. Create a file named composer.json with the following:

{
    "require": {
        "php-gcm/php-gcm": "1.1.0"
    }
}

And run Composer to install php-gcm:

$ curl -s http://getcomposer.org/installer | php
$ composer.phar install

Usage

$sender = new Sender($gcmApiKey);
$message = new Message($collapseKey, $payloadData);

try {
    $result = $sender->send($message, $deviceRegistrationId, $numberOfRetryAttempts);
} catch (\InvalidArgumentException $e) {
    // $deviceRegistrationId was null
} catch (PHP_GCM\InvalidRequestException $e) {
    // server returned HTTP code other than 200 or 503
} catch (\Exception $e) {
    // message could not be sent
}

License

php-gcm is licensed under the Apache 2.0 License

php-gcm is based heavily on Google's Java GCM server code