---
source_url: https://www.pubnub.com/docs/sdks/php/api-reference/mobile-push
title: Mobile Push Notifications API for PHP SDK
updated_at: 2026-06-04T11:12:29.323Z
sdk_name: PubNub PHP SDK
sdk_version: 9.0.0
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Mobile Push Notifications API for PHP SDK

PubNub PHP SDK, use the latest version: 9.0.0

Install:

```bash
composer require pubnub/pubnub@9.0.0
```

The Mobile Push Notifications feature connects native PubNub publishing to third-party push services. Supported services include Google Android FCM (Firebase Cloud Messaging) and Apple iOS APNs (Apple Push Notification service).

To learn more, read about [Mobile Push Notifications](https://www.pubnub.com/docs/general/push/send).

## Add a device to a push notifications channel

:::note Requires Mobile Push Notifications add-on
Enable Mobile Push Notifications for your key in the [Admin Portal](https://admin.pubnub.com/). See how to [enable add-on features](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-).
:::

Enable mobile push notifications on a set of channels.

### Method(s)

```php
$pubnub->addChannelsToPush()
    ->pushType(PNPushType)
    ->channels(array)
    ->deviceId(string)
    ->sync();
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| pushType | PNPushType | Yes | `Not set` | Accepted values: `PNPushType.FCM`, `PNPushType.APNS2`. |
| channels | Array | Yes |  | Channels to enable for push notifications. |
| deviceId | String | Yes |  | Device identifier. |
| environment | String | Optional | `development` | APNs environment. Required for `APNS2`. |
| topic | String | Optional |  | APNs topic (bundle identifier). Required for `APNS2`. |

### Sample code

#### Add device to channel (FCM)

:::tip Reference code
This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.
:::

```php
echo "🚀 Initializing PubNub Mobile Push Demo...\n";
echo "================================================\n\n";

$pnConfig = new PNConfiguration();
$pnConfig->setSubscribeKey(getenv('SUBSCRIBE_KEY') ?: 'demo');
$pnConfig->setPublishKey(getenv('PUBLISH_KEY') ?: 'demo');
$pnConfig->setUserId('php-mobile-push-demo-' . time());

$this->pubnub = new PubNub($pnConfig);

echo "✅ PubNub configured with demo keys\n";
echo "📱 User ID: " . $pnConfig->getUserId() . "\n\n";
$this->sampleChannels = [
    'news-channel-' . time(),
    'alerts-channel-' . time(),
    'promotions-channel-' . time(),
    'updates-channel-' . time()
];

$this->sampleDevices = [
    'fcm' => [
        'deviceId' => 'fcm-device-token-' . uniqid(),
        'pushType' => PNPushType::FCM,
        'name' => 'Android Device (FCM)'
    ],
    'apns2_dev' => [
        'deviceId' => 'apns2-dev-token-' . uniqid(),
        'pushType' => PNPushType::APNS2,
        'environment' => 'development',
        'topic' => 'com.example.myapp',
        'name' => 'iOS Device (APNS2 - Development)'
    ],
    'apns2_prod' => [
        'deviceId' => 'apns2-prod-token-' . uniqid(),
        'pushType' => PNPushType::APNS2,
        'environment' => 'production',
        'topic' => 'com.example.myapp',
        'name' => 'iOS Device (APNS2 - Production)'
    ]
];
$result = $this->pubnub->addChannelsToPush()
    ->pushType(PNPushType::FCM)
    ->channels($this->sampleChannels)
    ->deviceId($device['deviceId'])
    ->sync();
```

#### Add device to channel (APNS2)

```php
$result = $this->pubnub->addChannelsToPush()
    ->pushType(PNPushType::APNS2)
    ->channels($this->sampleChannels)
    ->deviceId($device['deviceId'])
    ->environment($device['environment'])
    ->topic($device['topic'])
    ->sync();
```

## List push notifications channels for a device

:::note Requires Mobile Push Notifications add-on
Enable Mobile Push Notifications for your key in the [Admin Portal](https://admin.pubnub.com/). See how to [enable add-on features](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-).
:::

List channels that have push notifications enabled for the specified device token.

### Method(s)

```php
$pubnub->listPushProvisions()
    ->pushType(PNPushType)
    ->deviceId(string)
    ->sync();
```

| Parameter | Description |
| --- | --- |
| `pushType` *Type: PNPushTypeDefault: `Not set` | Accepted values: `PNPushType.FCM`, `PNPushType.APNS2`. |
| `deviceId` *Type: StringDefault: n/a | Device token. |
| `environment`Type: StringDefault: `development` | APNs environment. Required for `APNS2`. |
| `topic`Type: StringDefault: n/a | APNs topic (bundle identifier). Required for `APNS2`. |

### Sample code

#### List channels for device

```php
$result = $this->pubnub->listPushProvisions()
    ->pushType(PNPushType::FCM)
    ->deviceId($device['deviceId'])
    ->sync();
```

#### List channels for Device(APNS2)

```php
$result = $this->pubnub->listPushProvisions()
    ->pushType(PNPushType::APNS2)
    ->deviceId($device['deviceId'])
    ->environment($device['environment'])
    ->topic($device['topic'])
    ->sync();
```

### Response

| Method | Description |
| --- | --- |
| `getChannels()`Type: Array | List of `channels` associated for mobile push notifications. |

## Remove a device from push notifications channels

:::note Requires Mobile Push Notifications add-on
Enable Mobile Push Notifications for your key in the [Admin Portal](https://admin.pubnub.com/). See how to [enable add-on features](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-).
:::

Disable mobile push notifications on a set of channels.

### Method(s)

```php
$pubnub->removeChannelsFromPush()
    ->pushType(PNPushType)
    ->channels(string|array)
    ->deviceId(string)
    ->sync();
```

| Parameter | Description |
| --- | --- |
| `pushType` *Type: PNPushTypeDefault: `Not set` | Accepted values: `PNPushType.FCM`, `PNPushType.APNS2`. |
| `channels` *Type: String|ArrayDefault: n/a | Channels to disable for push notifications. |
| `deviceId` *Type: StringDefault: n/a | Device token. |
| `environment`Type: StringDefault: `development` | APNs environment. Required for `APNS2`. |
| `topic`Type: StringDefault: n/a | APNs topic (bundle identifier). Required for `APNS2`. |

### Sample code

#### Remove device from channel

```php
$result = $this->pubnub->removeChannelsFromPush()
    ->pushType(PNPushType::FCM)
    ->channels($channelsToRemove)
    ->deviceId($device['deviceId'])
    ->sync();
```

#### Remove device from Channel(APNS2)

```php
$result = $this->pubnub->removeChannelsFromPush()
    ->pushType(PNPushType::APNS2)
    ->channels($channelsToRemove)
    ->deviceId($device['deviceId'])
    ->environment($device['environment'])
    ->topic($device['topic'])
    ->sync();
```

## Remove a device from all push notifications channels

:::note Requires Mobile Push Notifications add-on
Enable Mobile Push Notifications for your key in the [Admin Portal](https://admin.pubnub.com/). See how to [enable add-on features](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-).
:::

Disable mobile push notifications from all channels registered with the specified device token.

### Method(s)

```php
$pubnub->removeAllPushChannelsForDevice()
    ->pushType(PNPushType)
    ->deviceId(string)
    ->sync();
```

| Parameter | Description |
| --- | --- |
| `pushType` *Type: PNPushTypeDefault: `Not set` | Accepted values: `PNPushType.FCM`, `PNPushType.APNS2`. |
| `deviceId` *Type: StringDefault: n/a | Device token. |

### Sample code

#### Remove all push channels from device (FCM)

```php
$result = $this->pubnub->removeAllPushChannelsForDevice()
    ->pushType(PNPushType::FCM)
    ->deviceId($device['deviceId'])
    ->sync();
```

### Response

The `sync()` method returns a response indicating the success or failure of the operation. This could be a status code, boolean, or detailed object, depending on the implementation.

```php
$response = $this->pubnub->removeAllPushChannelsForDevice()
    ->pushType(PNPushType::APNS2)
    ->deviceId("yourDeviceId")
    ->sync();

if ($response->isSuccessful()) {
    echo "Successfully removed all push channels from device.";
} else {
    echo "Failed to remove push channels.";
}
```

## Terms in this document

* **Channel** - A pathway for sending and receiving messages between devices, created automatically when you first use it, that can handle any number of users and messages for different communication needs, like 1-1 text chats, group conversations, and other data streaming.
* **PubNub** - PubNub is a real-time messaging platform that provides APIs and SDKs for building scalable applications. It handles the complex infrastructure of real-time communication, including: Message delivery and persistence, Presence detection, Access control, Push notifications, File sharing, Serverless processing with Functions and Events & Actions, Analytics and monitoring with BizOps Workspace, AI-powered insights with Illuminate.