PHPackages                             baudev/fcm-xmpp - 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. baudev/fcm-xmpp

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

baudev/fcm-xmpp
===============

Allows XMPP connection with Firebase Cloud Messaging. It can listen upstream messages and send downstream ones.

1.1.0(6y ago)164982[1 issues](https://github.com/baudev/Firebase-Cloud-Messaging-FCM-XMPP/issues)MITPHPPHP &gt;=7.2

Since Jun 21Pushed 6y ago1 watchersCompare

[ Source](https://github.com/baudev/Firebase-Cloud-Messaging-FCM-XMPP)[ Packagist](https://packagist.org/packages/baudev/fcm-xmpp)[ RSS](/packages/baudev-fcm-xmpp/feed)WikiDiscussions master Synced 2mo ago

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

Firebase Cloud Messaging (FCM) XMPP - PHP
=========================================

[](#firebase-cloud-messaging-fcm-xmpp---php)

ServiceMasterDevelopCI Status[![Build Status](https://camo.githubusercontent.com/499f04b2791ed400e03df793f1fee6452b9443dc15ba29f9a6c75c525994136c/68747470733a2f2f7472617669732d63692e636f6d2f6261756465762f46697265626173652d436c6f75642d4d6573736167696e672d46434d2d584d50502e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/baudev/Firebase-Cloud-Messaging-FCM-XMPP)[![Build Status](https://camo.githubusercontent.com/f045e0bc83d8523f2f8499f841cb6f97d31a0a56cf462f4bee304093a7437684/68747470733a2f2f7472617669732d63692e636f6d2f6261756465762f46697265626173652d436c6f75642d4d6573736167696e672d46434d2d584d50502e7376673f6272616e63683d646576)](https://travis-ci.com/baudev/Firebase-Cloud-Messaging-FCM-XMPP)Version![Master version](https://camo.githubusercontent.com/69d46434f78e9c3146bb7a3d418ac24ccbe364bb567654b9475e277eb6364cc3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f64796e616d69632f6a736f6e2e7376673f75726c3d68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f6261756465762f46697265626173652d436c6f75642d4d6573736167696e672d46434d2d584d50502f6d61737465722f636f6d706f7365722e6a736f6e266c6162656c3d762671756572793d242e76657273696f6e26636f6c6f723d677265656e)![Develop version](https://camo.githubusercontent.com/af5c71e6bb4557d04cbd448c42571959688b9484ee34f0185b2172470fa107cb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f64796e616d69632f6a736f6e2e7376673f75726c3d68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f6261756465762f46697265626173652d436c6f75642d4d6573736167696e672d46434d2d584d50502f6465762f636f6d706f7365722e6a736f6e266c6162656c3d762671756572793d242e76657273696f6e26636f6c6f723d6f72616e6765)PHP version![PHP MINIMUM VERSION](https://camo.githubusercontent.com/46310f8b61520f5d5e187dbc0659afa6d1ea19252564283f05cd42bca2554961/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f64796e616d69632f6a736f6e2e7376673f75726c3d68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f6261756465762f46697265626173652d436c6f75642d4d6573736167696e672d46434d2d584d50502f6d61737465722f636f6d706f7365722e6a736f6e266c6162656c3d5048502671756572793d242e726571756972652e706870)![PHP MINIMUM VERSION](https://camo.githubusercontent.com/46310f8b61520f5d5e187dbc0659afa6d1ea19252564283f05cd42bca2554961/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f64796e616d69632f6a736f6e2e7376673f75726c3d68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f6261756465762f46697265626173652d436c6f75642d4d6573736167696e672d46434d2d584d50502f6d61737465722f636f6d706f7365722e6a736f6e266c6162656c3d5048502671756572793d242e726571756972652e706870)This PHP program, based on the unmaintained [sourc7/FCMStream](https://github.com/sourc7/FCMStream) repository, allows receiving and sending messages with the XMPP Protocol using [Firebase Cloud Messaging](https://firebase.google.com/docs/cloud-messaging/).

INSTALLATION
------------

[](#installation)

```
composer require baudev/fcm-xmpp

```

EXAMPLES
--------

[](#examples)

- Create an `index.php` file and write into it one of the two following script ([method1](#1-using-a-class-best-solution) or [method2](#2-using-function-callback-parameters)). Don't forget replacing : `SENDER_ID`, `SERVER KEY`.
- Run the script: `php index.php`

*Note: examples are provided in the directory `examples`. More explanations can be found into the [wiki page](https://github.com/baudev/Firebase-Cloud-Messaging-FCM-XMPP/wiki/References).*

### 1. Using a class (**best solution**):

[](#1-using-a-class-best-solution)

```
class YOURCLASSNAME extends \FCMStream\Core {

	public function onSend(string $from, string $messageId, Actions $actions) {
		 // TODO: Implement onSend() method.
	 }

	public function onReceipt(string $from, string $messageId, string $status, int $timestamp, Actions $actions)
         {
             // TODO: Implement onReceipt() method.
         }

	public function onReceiveMessage($data, int $timeToLive, string $from, string $messageId, string $packageName, Actions $actions) {
		// we answer to the message received
		$message = new \FCMStream\Message();
		$message->setTo($from);
		$message->setMessageId("message_id_test");
		$message->setPriority(\FCMStream\Message::PRIORITY_HIGH);
		$message->setData(array("test" => "Hello World!"));

		$actions->sendMessage($message);
	}

	/**
	 * The method is executed each X microseconds.
	 * To enable this method, you must execute enableOnLoopMethod()
	 * !! Warning !! Enabling this method can increase a lot the usage of your CPU!
	 * @param Actions $actions
	 */
	public function onLoop(Actions $actions)
	{
		// TODO: Implement onLoop() method.
	}

	public function onFail(?string $error, ?string $errorDescription, ?string $from, ?string $messageId, Actions $actions) {
		// TODO: Implement onFail() method.
	}

	public function onExpire(string $from, string $newFCMId, Actions $actions) {
	    // TODO: Implement onExpire() method.
	}
}

$test = new YOURCLASSNAME('SENDER_ID', 'SERVER KEY', 'debugfile.txt', \FCMStream\helpers\Logs::DEBUG);
// $test->enableOnLoopMethod(5 * 1000 * 1000); // enables the onLoop method. She will be called each 5 seconds.
// Before uncommenting the previous line, see https://github.com/baudev/Firebase-Cloud-Messaging-FCM-XMPP/wiki/References#enableonloopmethodmicroseconds
$test->stream();
```

### 2. Using function callback parameters:

[](#2-using-function-callback-parameters)

```
$test = new FCMStream\Callbacks('SENDER_ID', 'SERVER KEY', 'debugfile.txt', \FCMStream\helpers\Logs::ANY);

// onSend callback
$test->setOnSend(function (string $from, string $messageId, Actions $actions){
	// TODO: Implement onSend() method.
  });

// onReceipt callback
$test->setOnReceipt(function (string $from, string $messageId, string $status, int $timestamp, Actions $actions) {
	// TODO: Implement onReceipt() method.
});

// onReceiveMessage callback
$test->setOnReceiveMessage(function ($data, int $timeToLive, string $from, string $messageId, string $packageName, Actions $actions){
	// we answer to the message received
	$message = new \FCMStream\Message();
	$message->setTo($from);
	$message->setMessageId("message_id_test");
	$message->setPriority(\FCMStream\Message::PRIORITY_NORMAL);
	$message->setData(array("test" => "Hello World!"));

	$actions->sendMessage($message);
});

// onLoop callback
// To enable this method, you must execute enableOnLoopMethod()
// !! Warning !! Enabling this method can increase a lot the usage of your CPU!
$test->setOnLoop(function (Actions $actions) {
	// TODO: Implement onLoop() method.
});

// onFail callback
$test->setOnFail(function (?string $error, ?string $errorDescription, ?string $from, ?string $messageId, Actions $actions) {
	// TODO: Implement onFail() method.
  });

// onExpire callback
$test->setOnExpire(function (string $from, string $newFCMId, Actions $actions){
	// TODO: Implement onExpire() method.
  });

// $test->enableOnLoopMethod(5 * 1000 * 1000); // enables the onLoop method. She will be called each 5 seconds.
// Before uncommenting the previous line, see https://github.com/baudev/Firebase-Cloud-Messaging-FCM-XMPP/wiki/References#enableonloopmethodmicroseconds
$test->stream();
```

USAGE
-----

[](#usage)

1. **Downstream Messages**: server-to-device through FCM

[![](doc/downstream.png)](doc/downstream.png)

2. **Upstream Messages**: device-to-server through FCM

[![](doc/upstream.png)](doc/upstream.png)

DOCUMENTATION
-------------

[](#documentation)

See the [wiki page](https://github.com/baudev/Firebase-Cloud-Messaging-FCM-XMPP/wiki/References) to discover every possibilities provided by this framework.

### TODO

[](#todo)

- Add more comments
- Add methods for responding easily, to set message priority and so on. *Notification property is not handled yet*
- Improve README
- Add more tests

### CREDITS

[](#credits)

- Images in the [USAGE](#usage) part are coming from the [XAMARIN documentation](https://docs.microsoft.com/en-us/xamarin/android/data-cloud/google-messaging/google-cloud-messaging).
- Major part of the code is coming from the [sourc7/FCMStream](https://github.com/sourc7/FCMStream) repository. As it is unmaintained, I allow myself to fork it and improve it.

### LICENSE

[](#license)

```
MIT License

Copyright (c) 2016 Ante Radman (Radoid), Irvan Kurniawan (TechRapid), Baudev.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 90.2% 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 ~203 days

Total

3

Last Release

2473d ago

PHP version history (2 changes)v1.0.0PHP &gt;=7.1

1.0.1PHP &gt;=7.2

### Community

Maintainers

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

---

Top Contributors

[![baudev](https://avatars.githubusercontent.com/u/29781702?v=4)](https://github.com/baudev "baudev (83 commits)")[![sourc7](https://avatars.githubusercontent.com/u/8002742?v=4)](https://github.com/sourc7 "sourc7 (7 commits)")[![caveman99](https://avatars.githubusercontent.com/u/25002?v=4)](https://github.com/caveman99 "caveman99 (2 commits)")

---

Tags

fcmfirebase-cloud-messagingphpxmppphpcloudfirebaseFCMmessagingxmppupstreamDownstream

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/baudev-fcm-xmpp/health.svg)

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

###  Alternatives

[infobip/infobip-api-php-client

PHP library for consuming Infobip's API

921.8M10](/packages/infobip-infobip-api-php-client)[redjanym/php-firebase-cloud-messaging

PHP SDK for Firebase Cloud Messaging from Google

39847.9k1](/packages/redjanym-php-firebase-cloud-messaging)[redjanym/fcm-bundle

A Symfony Bundle for projects to send notifications in mobile devices through Firebase Cloud Messaging HTTP V1 API

43453.0k](/packages/redjanym-fcm-bundle)[coder966/fcm-simple

PHP library for Firebase Cloud Messaging

131.2k](/packages/coder966-fcm-simple)

PHPackages © 2026

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