Skip to content
forked from lkorth/php-gcm

An easy to use gcm library for PHP

License

Notifications You must be signed in to change notification settings

SakhCom/php-gcm

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

php-gcm

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

About

An easy to use gcm library for PHP

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%