# php-gcm

Why
--------
[Google Cloud Messaging for Android](http://developer.android.com/google/gcm/index.html) 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](http://developer.android.com/reference/com/google/android/gcm/server/package-summary.html)
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:

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

And run Composer to install php-gcm:

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

Usage
-------
```php
$sender = new Sender($key);
$message = new Message($collapseKey, $data);
$result = $sender->send($message, $devices, 5);
```

# php-gcm

Why
--------
[Google Cloud Messaging for Android](http://developer.android.com/google/gcm/index.html) 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](http://developer.android.com/reference/com/google/android/gcm/server/package-summary.html)
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:

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

And run Composer to install php-gcm:

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

Usage
-------
```php
$sender = new Sender($key);
$message = new Message($collapseKey, $data);

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

Add error handling to example
Add error handling to example
