{"id":19675371,"url":"https://github.com/baudev/firebase-cloud-messaging-fcm-xmpp","last_synced_at":"2025-10-24T14:45:35.682Z","repository":{"id":62492169,"uuid":"137736804","full_name":"baudev/Firebase-Cloud-Messaging-FCM-XMPP","owner":"baudev","description":"This PHP program allows receiving and sending messages with the XMPP Protocol using Firebase Cloud Messaging.","archived":false,"fork":false,"pushed_at":"2019-08-01T13:35:04.000Z","size":182,"stargazers_count":16,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-20T06:17:17.567Z","etag":null,"topics":["fcm","firebase-cloud-messaging","php","xmpp"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/baudev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-18T10:10:25.000Z","updated_at":"2024-05-19T14:11:32.000Z","dependencies_parsed_at":"2022-11-02T11:30:42.169Z","dependency_job_id":null,"html_url":"https://github.com/baudev/Firebase-Cloud-Messaging-FCM-XMPP","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baudev%2FFirebase-Cloud-Messaging-FCM-XMPP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baudev%2FFirebase-Cloud-Messaging-FCM-XMPP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baudev%2FFirebase-Cloud-Messaging-FCM-XMPP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baudev%2FFirebase-Cloud-Messaging-FCM-XMPP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/baudev","download_url":"https://codeload.github.com/baudev/Firebase-Cloud-Messaging-FCM-XMPP/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251420884,"owners_count":21586697,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fcm","firebase-cloud-messaging","php","xmpp"],"created_at":"2024-11-11T17:23:31.153Z","updated_at":"2025-10-24T14:45:30.646Z","avatar_url":"https://github.com/baudev.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Firebase Cloud Messaging (FCM) XMPP - PHP  \n\n| Service | Master | Develop\n|:--:|:--:|:--:\n| CI Status | [![Build Status](https://travis-ci.com/baudev/Firebase-Cloud-Messaging-FCM-XMPP.svg?branch=master)](https://travis-ci.com/baudev/Firebase-Cloud-Messaging-FCM-XMPP) | [![Build Status](https://travis-ci.com/baudev/Firebase-Cloud-Messaging-FCM-XMPP.svg?branch=dev)](https://travis-ci.com/baudev/Firebase-Cloud-Messaging-FCM-XMPP)\n| Version |  [![Master version](https://img.shields.io/badge/dynamic/json.svg?url=https://raw.githubusercontent.com/baudev/Firebase-Cloud-Messaging-FCM-XMPP/master/composer.json\u0026label=v\u0026query=$.version\u0026color=green)]() | [![Develop version](https://img.shields.io/badge/dynamic/json.svg?url=https://raw.githubusercontent.com/baudev/Firebase-Cloud-Messaging-FCM-XMPP/dev/composer.json\u0026label=v\u0026query=$.version\u0026color=orange)]()\n| PHP version | [![PHP MINIMUM VERSION](https://img.shields.io/badge/dynamic/json.svg?url=https://raw.githubusercontent.com/baudev/Firebase-Cloud-Messaging-FCM-XMPP/master/composer.json\u0026label=PHP\u0026query=$.require.php)]() | [![PHP MINIMUM VERSION](https://img.shields.io/badge/dynamic/json.svg?url=https://raw.githubusercontent.com/baudev/Firebase-Cloud-Messaging-FCM-XMPP/master/composer.json\u0026label=PHP\u0026query=$.require.php)]() |\n\nThis 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/).  \n  \n## INSTALLATION  \n\n```\ncomposer require baudev/fcm-xmpp  \n```\n\n## EXAMPLES  \n- 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`.\n- Run the script: `php index.php`\n\n*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).*\n\n### 1. Using a class (**best solution**):   \n```php  \nclass YOURCLASSNAME extends \\FCMStream\\Core {  \n  \n\tpublic function onSend(string $from, string $messageId, Actions $actions) { \n\t\t // TODO: Implement onSend() method. \n\t }  \n\t \n\tpublic function onReceipt(string $from, string $messageId, string $status, int $timestamp, Actions $actions)\n         {\n             // TODO: Implement onReceipt() method. \n         }\n \n\tpublic function onReceiveMessage($data, int $timeToLive, string $from, string $messageId, string $packageName, Actions $actions) { \n\t\t// we answer to the message received \n\t\t$message = new \\FCMStream\\Message();  \n\t\t$message-\u003esetTo($from);  \n\t\t$message-\u003esetMessageId(\"message_id_test\");  \n\t\t$message-\u003esetPriority(\\FCMStream\\Message::PRIORITY_HIGH);  \n\t\t$message-\u003esetData(array(\"test\" =\u003e \"Hello World!\")); \n\t\t \n\t\t$actions-\u003esendMessage($message);\n\t}  \n\t\n\t/**\n\t * The method is executed each X microseconds.\n\t * To enable this method, you must execute enableOnLoopMethod()\n\t * !! Warning !! Enabling this method can increase a lot the usage of your CPU!\n\t * @param Actions $actions\n\t */\n\tpublic function onLoop(Actions $actions)\n\t{\n\t\t// TODO: Implement onLoop() method. \n\t}\n\n\tpublic function onFail(?string $error, ?string $errorDescription, ?string $from, ?string $messageId, Actions $actions) { \n\t\t// TODO: Implement onFail() method. \n\t}  \n\t\n\tpublic function onExpire(string $from, string $newFCMId, Actions $actions) { \n\t    // TODO: Implement onExpire() method. \n\t}\n}  \n  \n$test = new YOURCLASSNAME('SENDER_ID', 'SERVER KEY', 'debugfile.txt', \\FCMStream\\helpers\\Logs::DEBUG); \n// $test-\u003eenableOnLoopMethod(5 * 1000 * 1000); // enables the onLoop method. She will be called each 5 seconds. \n// Before uncommenting the previous line, see https://github.com/baudev/Firebase-Cloud-Messaging-FCM-XMPP/wiki/References#enableonloopmethodmicroseconds\n$test-\u003estream();  \n```\n\n### 2. Using function callback parameters:\n\n```php  \n$test = new FCMStream\\Callbacks('SENDER_ID', 'SERVER KEY', 'debugfile.txt', \\FCMStream\\helpers\\Logs::ANY);  \n  \n// onSend callback  \n$test-\u003esetOnSend(function (string $from, string $messageId, Actions $actions){  \n\t// TODO: Implement onSend() method.\n  });  \n  \n// onReceipt callback\n$test-\u003esetOnReceipt(function (string $from, string $messageId, string $status, int $timestamp, Actions $actions) {\n\t// TODO: Implement onReceipt() method.\n});\n  \n// onReceiveMessage callback  \n$test-\u003esetOnReceiveMessage(function ($data, int $timeToLive, string $from, string $messageId, string $packageName, Actions $actions){ \n\t// we answer to the message received \n\t$message = new \\FCMStream\\Message();  \n\t$message-\u003esetTo($from);  \n\t$message-\u003esetMessageId(\"message_id_test\");  \n\t$message-\u003esetPriority(\\FCMStream\\Message::PRIORITY_NORMAL);  \n\t$message-\u003esetData(array(\"test\" =\u003e \"Hello World!\"));  \n\t\n\t$actions-\u003esendMessage($message);  \n});\n\n// onLoop callback\n// To enable this method, you must execute enableOnLoopMethod()\n// !! Warning !! Enabling this method can increase a lot the usage of your CPU!\n$test-\u003esetOnLoop(function (Actions $actions) {\n\t// TODO: Implement onLoop() method. \n});\n  \n// onFail callback  \n$test-\u003esetOnFail(function (?string $error, ?string $errorDescription, ?string $from, ?string $messageId, Actions $actions) { \n\t// TODO: Implement onFail() method. \n  });  \n  \n// onExpire callback  \n$test-\u003esetOnExpire(function (string $from, string $newFCMId, Actions $actions){  \n\t// TODO: Implement onExpire() method. \n  });  \n  \n// $test-\u003eenableOnLoopMethod(5 * 1000 * 1000); // enables the onLoop method. She will be called each 5 seconds.\n// Before uncommenting the previous line, see https://github.com/baudev/Firebase-Cloud-Messaging-FCM-XMPP/wiki/References#enableonloopmethodmicroseconds\n$test-\u003estream();  \n```  \n  \n## USAGE  \n  \n1. **Downstream Messages**: server-to-device through FCM  \n  \n![](doc/downstream.png)  \n  \n2. **Upstream Messages**: device-to-server through FCM  \n  \n![](doc/upstream.png)    \n\n## DOCUMENTATION\n\nSee the [wiki page](https://github.com/baudev/Firebase-Cloud-Messaging-FCM-XMPP/wiki/References) to discover every possibilities provided by this framework.\n\n### TODO  \n  \n- [X] Add more comments\n- [X] Add methods for responding easily, to set message priority and so on. *Notification property is not handled yet*  \n- [X] Improve README\n- [ ] Add more tests  \n  \n### CREDITS  \n  \n- 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).  \n- 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.  \n  \n### LICENSE  \n  \n```  \nMIT License  \n  \nCopyright (c) 2016 Ante Radman (Radoid), Irvan Kurniawan (TechRapid), Baudev.  \n  \nPermission is hereby granted, free of charge, to any person obtaining a copy  \nof this software and associated documentation files (the \"Software\"), to deal  \nin the Software without restriction, including without limitation the rights  \nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell  \ncopies of the Software, and to permit persons to whom the Software is  \nfurnished to do so, subject to the following conditions:  \n  \nThe above copyright notice and this permission notice shall be included in all  \ncopies or substantial portions of the Software.  \n  \nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  \nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  \nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE  \nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  \nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,  \nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE  \nSOFTWARE.  \n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaudev%2Ffirebase-cloud-messaging-fcm-xmpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbaudev%2Ffirebase-cloud-messaging-fcm-xmpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaudev%2Ffirebase-cloud-messaging-fcm-xmpp/lists"}