php-gcm/php-gcm

This package is abandoned and no longer maintained. No replacement package was suggested.

A PHP library for sending GCM messages

1.1.1 2015-05-06 13:25 UTC

This package is not auto-updated.

Last update: 2020-01-21 13:38:30 UTC


README

Build Status Total Downloads

Why

Google Cloud Messaging for Android is very powerful, but there are a lot of details to handle. This library takes care of the details and makes GCM very easy to use with PHP.

Support

php-gcm supports the HTTP server protocol for GCM. There is not currently support for XMPP, but implementations and pull requests for XMPP are welcome. See #3 for more details.

php-gcm supports PHP versions >= 5.3.10. php-gcm may work on older versions of PHP, but has not been tested on them.

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.1"
    }
}

And run Composer to install php-gcm:

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

Latest

php-gcm follows SEMVER. If you would like to try out the latest, possibly unstable or incorrect code, the dependency can be pointed to dev-master.

{
    "require": {
        "php-gcm/php-gcm": "dev-master"
    }
}

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. See the LICENSE file for more details.