PHPackages                             codemonkeys-ru/gcm-message - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. codemonkeys-ru/gcm-message

ActiveLibrary

codemonkeys-ru/gcm-message
==========================

Google Cloud Messaging (GCM) PHP Server Library

v0.5(9y ago)6389.9k↓29.6%21[1 PRs](https://github.com/CodeMonkeysRu/GCMMessage/pulls)MITPHPPHP &gt;=5.6

Since Apr 22Pushed 9y ago8 watchersCompare

[ Source](https://github.com/CodeMonkeysRu/GCMMessage)[ Packagist](https://packagist.org/packages/codemonkeys-ru/gcm-message)[ RSS](/packages/codemonkeys-ru-gcm-message/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (2)Versions (6)Used By (0)

Google Cloud Messaging (GCM) PHP Server Library
-----------------------------------------------

[](#google-cloud-messaging-gcm-php-server-library)

A PHP library for sending messages to devices registered through Google Cloud Messaging [![Build Status](https://camo.githubusercontent.com/ca045c5fd59feac890875f2fd4948314edca0ea542a1fc89b0a8112ee9ec977d/68747470733a2f2f7472617669732d63692e6f72672f436f64654d6f6e6b65797352752f47434d4d6573736167652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/CodeMonkeysRu/GCMMessage)

See:

Example usage
-------------

[](#example-usage)

```
use \CodeMonkeysRu\GCM;

$sender = new GCM\Sender("YOUR GOOGLE API KEY");

$message = new GCM\Message(
        array("device_registration_id1", "device_registration_id2"),
        array("data1" => "123", "data2" => "string")
);

$message
    ->notification(array("title" => "foo", "body" => "bar"))
    ->setCollapseKey("collapse_key")
    ->setDelayWhileIdle(true)
    ->setTtl(123)
    ->setRestrictedPackageName("com.example.trololo")
    ->setDryRun(true)
    ->setPriority(GCM\MessageMessage::PRIORITY_HIGH)
;

try {
    $response = $sender->send($message);

    if ($response->getNewRegistrationIdsCount() > 0) {
        $newRegistrationIds = $response->getNewRegistrationIds();
        foreach ($newRegistrationIds as $oldRegistrationId => $newRegistrationId){
            //Update $oldRegistrationId to $newRegistrationId in DB
            //TODO
        }
    }

    if ($response->getFailureCount() > 0) {
        $invalidRegistrationIds = $GCMresponse->getInvalidRegistrationIds();
        foreach($invalidRegistrationIds as $invalidRegistrationId) {
            //Remove $invalidRegistrationId from DB
            //TODO
        }

        //Schedule to resend messages to unavailable devices
        $unavailableIds = $response->getUnavailableRegistrationIds();
        //TODO
    }
} catch (GCM\Exception $e) {

    switch ($e->getCode()) {
        case GCM\Exception::ILLEGAL_API_KEY:
        case GCM\Exception::AUTHENTICATION_ERROR:
        case GCM\Exception::MALFORMED_REQUEST:
        case GCM\Exception::UNKNOWN_ERROR:
        case GCM\Exception::MALFORMED_RESPONSE:
            //Deal with it
            break;
    }
}
```

Also indirect message API available

```
use \CodeMonkeysRu\GCM;

$sender = new GCM\Sender("YOUR GOOGLE API KEY");

try {
    $response = $sender->sendMessage(
        array("device_registration_id1", "device_registration_id2"),
        array("data1" => "123", "data2" => "string"),
        "collapse_key"
    );

    if ($response->getNewRegistrationIdsCount() > 0) {
        $newRegistrationIds = $response->getNewRegistrationIds();
        foreach ($newRegistrationIds as $oldRegistrationId => $newRegistrationId){
            //Update $oldRegistrationId to $newRegistrationId in DB
            //TODO
        }
    }

    if ($response->getFailureCount() > 0) {
        $invalidRegistrationIds = $GCMresponse->getInvalidRegistrationIds();
        foreach($invalidRegistrationIds as $invalidRegistrationId) {
            //Remove $invalidRegistrationId from DB
            //TODO
        }

        //Schedule to resend messages to unavailable devices
        $unavailableIds = $response->getUnavailableRegistrationIds();
        //TODO
    }
} catch (GCM\Exception $e) {

    switch ($e->getCode()) {
        case GCM\Exception::ILLEGAL_API_KEY:
        case GCM\Exception::AUTHENTICATION_ERROR:
        case GCM\Exception::MALFORMED_REQUEST:
        case GCM\Exception::UNKNOWN_ERROR:
        case GCM\Exception::MALFORMED_RESPONSE:
            //Deal with it
            break;
    }
}
```

Note about cURL SSL verify peer option
--------------------------------------

[](#note-about-curl-ssl-verify-peer-option)

Library has turned off CURLOPT\_SSL\_VERIFYPEER by default, but you can enable it by passing third parameter into constructor of Sender class.

You need to [download](http://curl.haxx.se/docs/caextract.html) root certificates and add them somewhere into your project directory. Then construct Sender object like this:

```
use \CodeMonkeysRu\GCM;

$sender = new GCM\Sender("YOUR GOOGLE API KEY", false, "/path/to/cacert.crt");
```

ChangeLog
---------

[](#changelog)

- v0.5 - Added support for "priority" flag ([\#16](https://github.com/CodeMonkeysRu/GCMMessage/pull/16))
- v0.4 - Code cleanup, PHP5.5 support dropped
- v0.3 - Content-available added ([\#11](https://github.com/CodeMonkeysRu/GCMMessage/pull/11))
- v0.2 - Notifications added
- v0.1 - Initial release

Licensed under MIT license.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity45

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 62.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~340 days

Total

5

Last Release

3412d ago

PHP version history (2 changes)0.1PHP &gt;=5.3.2

v0.4PHP &gt;=5.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/d666a6f600ef2eaf99c9810947d642b9465b0a32f6e72b158158afc4562f6981?d=identicon)[iVariable](/maintainers/iVariable)

---

Top Contributors

[![iVariable](https://avatars.githubusercontent.com/u/427486?v=4)](https://github.com/iVariable "iVariable (22 commits)")[![joeykrim](https://avatars.githubusercontent.com/u/208641?v=4)](https://github.com/joeykrim "joeykrim (4 commits)")[![mryvlin](https://avatars.githubusercontent.com/u/3071413?v=4)](https://github.com/mryvlin "mryvlin (3 commits)")[![vasayxtx](https://avatars.githubusercontent.com/u/545171?v=4)](https://github.com/vasayxtx "vasayxtx (3 commits)")[![vladimirsavenkov](https://avatars.githubusercontent.com/u/10205806?v=4)](https://github.com/vladimirsavenkov "vladimirsavenkov (2 commits)")[![stevetauber](https://avatars.githubusercontent.com/u/1258342?v=4)](https://github.com/stevetauber "stevetauber (1 commits)")

---

Tags

gcmandroidpush message

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/codemonkeys-ru-gcm-message/health.svg)

```
[![Health](https://phpackages.com/badges/codemonkeys-ru-gcm-message/health.svg)](https://phpackages.com/packages/codemonkeys-ru-gcm-message)
```

###  Alternatives

[sly/notification-pusher

Standalone PHP library for easy devices notifications push.

1.2k2.8M15](/packages/sly-notification-pusher)[paragraph1/php-fcm

PHP application server for google firebase cloud messaging (FCM)

1991.2M10](/packages/paragraph1-php-fcm)[kedniko/firebase-cloud-messaging-http-v1-php

Firebase cloud messaging http v1 php

124.8k](/packages/kedniko-firebase-cloud-messaging-http-v1-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
