PHPackages                             volk/php-firebase-cloud-messaging - 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. [API Development](/categories/api)
4. /
5. volk/php-firebase-cloud-messaging

ActiveLibrary[API Development](/categories/api)

volk/php-firebase-cloud-messaging
=================================

Firebase Cloud Messaging (FCM) SDK for PHP applications

00PHP

Since Apr 14Pushed 1y ago1 watchersCompare

[ Source](https://github.com/olucvolkan/fcm-php-sdk)[ Packagist](https://packagist.org/packages/volk/php-firebase-cloud-messaging)[ RSS](/packages/volk-php-firebase-cloud-messaging/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHP Client for Firebase Cloud Messaging (FCM)
=============================================

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

Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably send notifications at no cost. Using FCM, you can notify a client app that new email or other data is available to sync. You can send notification messages to drive user re-engagement and retention.

This PHP SDK provides a clean and simple way to send push notifications with Firebase Cloud Messaging from your PHP applications.

[![Latest Stable Version](https://camo.githubusercontent.com/2630be6fb65e44458d7647202ee075ee4c0790a645092f78c0ab12a295161043/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f766f6c6b2f7068702d66697265626173652d636c6f75642d6d6573736167696e672e737667)](https://packagist.org/packages/volk/php-firebase-cloud-messaging)[![License](https://camo.githubusercontent.com/8859f7122b1dd41f8720f3983d6ccc23050cd33d829fb912e387b976fc915131/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f766f6c6b2f7068702d66697265626173652d636c6f75642d6d6573736167696e672e737667)](https://github.com/olucvolkan/fcm-php-sdk/blob/master/LICENSE)[![PHP Version](https://camo.githubusercontent.com/53c11f5819f53fb6c1ec5a6c82e4a2b910676fc9791fa1bbbea1833dc0b587e4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f766f6c6b2f7068702d66697265626173652d636c6f75642d6d6573736167696e672e737667)](https://packagist.org/packages/volk/php-firebase-cloud-messaging)

Features
--------

[](#features)

- Compatible with PHP 7.1+ and Laravel 5.5+
- Send notifications to single devices, multiple devices (up to 1000), or topics
- Support for notification messages (visible) and data messages (invisible payload)
- Configure message priority, time to live, and more
- Laravel integration with auto-discovery and notification channel
- Symfony integration
- Easy to use and extend

Installation
------------

[](#installation)

```
composer require volk/php-firebase-cloud-messaging
```

Laravel 5.5+ Integration
------------------------

[](#laravel-55-integration)

This package supports Laravel 5.5+ with auto-discovery. Once you install the package, it will be automatically registered.

Add your Firebase Server Key to your `.env` file:

```
FCM_SERVER_KEY=your_firebase_server_key_here

```

And add the configuration to `config/services.php`:

```
'fcm' => [
    'key' => env('FCM_SERVER_KEY'),
],
```

Then you can use the Facade:

```
use Firebase\CloudMessaging\Laravel\Facades\FCM;
use Firebase\CloudMessaging\RequestResponse\Message;

$message = new Message();
$message->setNotification([...]);
$response = FCM::send($message);
```

Or use the notification channel:

```
// Create a notification class
class PushNotification extends Notification
{
    public function via($notifiable)
    {
        return ['fcm'];
    }

    public function toFcm($notifiable)
    {
        return (new Message())
            ->setNotification([
                'title' => 'Notification Title',
                'body' => 'Notification Body',
            ])
            ->setToken($notifiable->fcm_token);
    }
}

// Send the notification
$user->notify(new PushNotification());
```

Basic Usage
-----------

[](#basic-usage)

```
// Initialize the FCM client with your Firebase server key
$fcmClient = new FCMClient('YOUR_FIREBASE_SERVER_KEY');

// Create a new message
$message = new Message();

// Configure the notification (visible to users)
$message
    ->setNotification([
        'title' => 'Hello World',
        'body' => 'This is a test notification',
        'sound' => 'default',
        'badge' => '1'
    ])
    // Add message data (invisible payload)
    ->setData([
        'key1' => 'value1',
        'key2' => 'value2'
    ])
    // Target a specific device
    ->setToken('DEVICE_FCM_TOKEN')
    // Or target multiple devices
    // ->setTokens(['TOKEN1', 'TOKEN2', 'TOKEN3'])
    // Or target a topic
    // ->setTopic('news')
    // Add optional parameters
    ->setPriority(Priority::HIGH)
    ->setTimeToLive(86400); // 1 day in seconds

// Send the message
$response = $fcmClient->send($message);

// Check the response
echo $response->getStatusCode(); // 200 if successful
$result = $response->getResult();
```

Targeting Options
-----------------

[](#targeting-options)

FCM messages can be sent to three types of targets:

1. **Single Device**: Send to a specific FCM registration token

    ```
    $message->setToken('DEVICE_FCM_TOKEN');
    ```
2. **Multiple Devices**: Send to multiple FCM registration tokens (up to 1000 tokens)

    ```
    $message->setTokens(['TOKEN1', 'TOKEN2', 'TOKEN3']);
    ```
3. **Topic**: Send to devices subscribed to a topic

    ```
    $message->setTopic('news');
    ```

Message Types
-------------

[](#message-types)

### Notification Messages

[](#notification-messages)

Notification messages display an alert, badge, or sound to notify the user about an incoming message. FCM handles displaying the notification on the user's device.

```
$message->setNotification([
    'title' => 'Notification Title',
    'body' => 'Notification Body',
    'image' => 'https://example.com/image.png', // Optional
    'sound' => 'default',
    'badge' => '1',
    'click_action' => 'OPEN_ACTIVITY' // Optional: action when notification is tapped
]);
```

### Data Messages

[](#data-messages)

Data messages contain your custom key-value pairs that are invisible to the user. Your client app is responsible for processing data messages.

```
$message->setData([
    'score' => '850',
    'time' => '2:45',
    'type' => 'sports',
    'custom_data' => '{"key": "value"}'
]);
```

Advanced Options
----------------

[](#advanced-options)

### Message Priority

[](#message-priority)

Set the priority of the message:

```
// Available options: Priority::HIGH, Priority::NORMAL
$message->setPriority(Priority::HIGH);
```

### Time To Live (TTL)

[](#time-to-live-ttl)

Set how long (in seconds) the message should be kept if the device is offline:

```
$message->setTimeToLive(259200); // 3 days in seconds
```

### Collapse Key

[](#collapse-key)

Group multiple messages with the same collapse key to ensure only the last message is delivered when the device comes online:

```
$message->setCollapseKey('updates');
```

### Content Available

[](#content-available)

For iOS, enable background updates when data arrives:

```
$message->setContentAvailable(true);
```

### Mutable Content

[](#mutable-content)

For iOS, allow notification service extensions to modify the notification:

```
$message->setMutableContent(true);
```

Error Handling
--------------

[](#error-handling)

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

    if ($response->isSuccess()) {
        echo "Message sent successfully!";
        $result = $response->getResult();

        // Check for successful tokens
        if (isset($result['success'])) {
            echo "Successful messages: " . $result['success'];
        }

        // Check for failed tokens
        if (isset($result['failure'])) {
            echo "Failed messages: " . $result['failure'];

            // Get detailed error information
            foreach ($result['results'] as $index => $tokenResult) {
                if (isset($tokenResult['error'])) {
                    echo "Token at index $index failed: " . $tokenResult['error'];
                }
            }
        }
    } else {
        echo "Failed to send message. Status code: " . $response->getStatusCode();
        echo "Error message: " . $response->getErrorMessage();
    }
} catch (FCMException $e) {
    echo "FCM error: " . $e->getMessage();
} catch (\Exception $e) {
    echo "Error: " . $e->getMessage();
}
```

Response Fields
---------------

[](#response-fields)

FieldTypeDescriptionmulticast\_idstringUnique ID identifying the multicast messagesuccessintegerNumber of messages that were successfully processedfailureintegerNumber of messages that could not be processedcanonical\_idsintegerNumber of results with canonical registration tokenresultsarrayArray of objects representing the status of each tokenExamples
--------

[](#examples)

Check the `examples` directory for more detailed examples:

- [Simple notification example](examples/simple_notification.php)
- [Laravel integration example](examples/laravel_integration.php)
- [Laravel 5.5 specific integration example](examples/laravel55_integration.php)
- [Symfony integration example](examples/symfony_integration.php)

Development &amp; Contribution
------------------------------

[](#development--contribution)

Contributions are welcome! Please feel free to submit a Pull Request.

License
-------

[](#license)

This project is licensed under the MIT License - see the LICENSE file for details.

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity15

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.

### Community

Maintainers

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

---

Top Contributors

[![olucvolkan](https://avatars.githubusercontent.com/u/13987389?v=4)](https://github.com/olucvolkan "olucvolkan (38 commits)")

### Embed Badge

![Health badge](/badges/volk-php-firebase-cloud-messaging/health.svg)

```
[![Health](https://phpackages.com/badges/volk-php-firebase-cloud-messaging/health.svg)](https://phpackages.com/packages/volk-php-firebase-cloud-messaging)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[facebook/php-business-sdk

PHP SDK for Facebook Business

90821.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

74513.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

265103.1M454](/packages/google-gax)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)

PHPackages © 2026

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