A PHP library for sending GCM messages

Installs: 11 988

Dependents: 3

Stars: 91

Watchers: 10

Forks: 22

Open Issues: 4

1.1.1 2015-05-06 13:25 UTC



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 Java library and makes GCM very easy and powerful in PHP.


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 | php
$ composer.phar install


$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


php-gcm is licensed under the Apache 2.0 License

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