httd1 / fcmclient
A simple FCM client for PHP
v1.0.0
2025-08-28 22:43 UTC
Requires
- php: ^8.0
- firebase/php-jwt: ^6.11
- guzzlehttp/guzzle: ^7.10
This package is auto-updated.
Last update: 2025-08-28 23:09:24 UTC
README
A simple PHP client to send messages with Firebase Cloud Messaging (FCM) using the HTTP v1 API.
It does not rely on the official Google SDK, only guzzlehttp/guzzle
and firebase/php-jwt
.
📦 Installation
Install via Composer:
composer require httd1/fcmclient
⚙️ Setup
Download the private key JSON file in the Firebase Console.
Place this file in your project, ex. firebase-credentials.json.
🚀 Usage
Send to a single device
<?php require 'vendor/autoload.php'; use FcmClient\FcmClient; try { // initialize client with service account JSON $client = new FcmClient(__DIR__ . '/firebase-credentials.json'); // send notification $response = $client->send([ 'message' => [ 'token' => 'FCM_DEVICE_TOKEN_HERE', 'notification' => [ 'title' => 'Hello!', 'body' => 'Test notification 🚀' ] ] ]); print_r($response); } catch (\Throwable $e) { echo 'Error: ' . $e->getMessage(); }
Send to a topic
$response = $client->send([ 'message' => [ 'topic' => 'my_app_topic', 'notification' => [ 'title' => 'Update', 'body' => 'Message sent to all subscribers of the topic' ] ] ]); print_r($response);
Send with custom data payload
$response = $client->send([ 'message' => [ 'token' => 'FCM_DEVICE_TOKEN_HERE', 'data' => [ 'action' => 'open_chat', 'chat_id' => '12345' ] ] ]);