PHPackages                             mve/fcm-php - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. mve/fcm-php

ActiveLibrary[HTTP &amp; Networking](/categories/http)

mve/fcm-php
===========

Send Google Firebase Cloud messages

v0.3.2(5mo ago)0267MITPHPPHP &gt;=8.1

Since Aug 11Pushed 5mo agoCompare

[ Source](https://github.com/michielvaneerd/fcm-php)[ Packagist](https://packagist.org/packages/mve/fcm-php)[ RSS](/packages/mve-fcm-php/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (5)Versions (3)Used By (0)

Firebase Cloud Messaging for PHP
================================

[](#firebase-cloud-messaging-for-php)

Send Google Firebase Cloud messages with PHP.

API documentation
-----------------

[](#api-documentation)

See [API documentation](https://michielvaneerd.github.io/fcm-php/)

Preparation
-----------

[](#preparation)

First make sure you have a Firebase project and you have downloaded the private key JSON file. See  for more information.

Each call to the The Google API has to be authenticated with an access token that is fetched from the Google API. These access tokens expire after an hour. This library will take care of getting an access token from the Google API and cache it for an hour. However it doesn't implement a caching mechanism itself, but it expects an implementation of the [`Mve\FcmPhp\Models\CacheInterface`](https://michielvaneerd.github.io/fcm-php/classes/Mve-FcmPhp-Models-CacheInterface.html) from the caller.

Getting started
---------------

[](#getting-started)

Sending messages is done with the `Messaging` class:

```
$messaging = new Messaging(new MyCache(), '/path/to/file.json', Log::getLogger());
```

The arguments:

1. An instance of a `Mve\FcmPhp\Models\CacheInterface` implementation as explained earlier.
2. The path to the Google Firebase private key JSON file.
3. An optional `Psr\Log\LoggerInterface` implementation. This is only needed if you want to see the requests and responses logged.

Sending messages to devices
---------------------------

[](#sending-messages-to-devices)

The `sendAll` method uses HTTP/2 multiplexing. It's very fast and can be used to send a batch of notifications.

```
// Create messages. The first argument is the ID - this can be used to map the result to the specific message after sending.
$messages = [
    new TokenMessage(1, 'token1', "Content of notification", "Title of notification"),
    new TokenMessage(2, 'token1', "Content of notification", "Title of notification")
];
// Send the messages
try {
    $sendResult = $messaging->sendAll($messages);
    foreach ($sendResult->getSent() as $messageId => $firebaseId) {
        // Successfully sent messages
    }
    foreach ($sendResult->getUnregistered() as $messageId => $fcmError) {
        // The tokens for these messages can be deleted safely.
    }
    foreach ($sendResult->getErrors() as $messageId => $fcmError) {
        // See the $fcmError for specifics about this error.
    }
} catch (\Mve\FcmPhp\Models\FcmException $ex) {
    // This is bad, but it's at least an error we got from the Google API
    die('Exception from the Google API: ' . $ex->fcmError->content);
} catch (\Exception $ex) {
    // This is also bad, and it's a non Google API exception, maybe network error?
    die('Some other exception: ' . $ex->getMessage());
}
```

Testing
-------

[](#testing)

First make sure the environment variable `JSON_FILE` points to your Google Firebase private key JSON file:

`export JSON_FILE="/path/to/file.json"`

If you want to test one or more valid registration tokens, set then to the `TOKENS` environment variable:

`export TOKENS="token1, token2"`

If you already have an access token that you want to use during the tests, you can set it with:

`export ACCESS_TOKEN="my-access-token"`

### Test getting a valid access token

[](#test-getting-a-valid-access-token)

This will test getting an access token from the Google API.

`./vendor/bin/phpunit tests/AccessTokenHandlerTest.php`

### Test invalid registration tokens

[](#test-invalid-registration-tokens)

This will test some invalid tokens.

`./vendor/bin/phpunit tests/MessagingWithoutEnvTokenTest.php`

### Test valid registration tokens

[](#test-valid-registration-tokens)

This will test one or more valid tokens.

Only works if you have set the `TOKENS` environment variable.

`./vendor/bin/phpunit tests/MessagingWithEnvTokenTest.php`

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance73

Regular maintenance activity

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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 ~164 days

Total

2

Last Release

152d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/88331b2278375f6e5f6b765d5fe4309fc9c74395733a366963061d5ab6a635e3?d=identicon)[michielve](/maintainers/michielve)

---

Top Contributors

[![michielvaneerd](https://avatars.githubusercontent.com/u/375532?v=4)](https://github.com/michielvaneerd "michielvaneerd (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mve-fcm-php/health.svg)

```
[![Health](https://phpackages.com/badges/mve-fcm-php/health.svg)](https://phpackages.com/packages/mve-fcm-php)
```

###  Alternatives

[symfony/http-kernel

Provides a structured process for converting a Request into a Response

8.1k853.6M8.3k](/packages/symfony-http-kernel)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.4M196](/packages/sulu-sulu)[web-auth/webauthn-framework

FIDO2/Webauthn library for PHP and Symfony Bundle.

51090.8k2](/packages/web-auth-webauthn-framework)[kimai/kimai

Kimai - Time Tracking

4.7k8.7k1](/packages/kimai-kimai)[bitrix24/b24phpsdk

An official PHP library for the Bitrix24 REST API

10139.4k5](/packages/bitrix24-b24phpsdk)[api-platform/metadata

API Resource-oriented metadata attributes and factories

244.5M182](/packages/api-platform-metadata)

PHPackages © 2026

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