Docs

  • Channels Channels
  • Beams Beams
  • Developers
  • Support
  • Blog
  • Sign up
    • Search powered by Algolia
    • Sign in
    • Sign up
    • Channels
    • Beams
    • Getting started
      • Android
        • 1. Configure FCM
        • 2. Integrate SDK
        • 3. Initialize Beams
        • 4. Publish Notifications
      • iOS
        • 1. Configure APNS
        • 2. Integrate SDK
        • 3. Publish Notifications
      • Web
        • 1. SDK integration
        • 2. Safari configuration
      • Flutter
        • 1. Configure FCM and APNS
        • 2. Integrate SDK
        • 4. Publish Notifications
    • Concepts
      • Subscribers
      • Device interests
      • Authenticated users
      • Insights
      • Webhooks
    • Guides
      • Handle incoming notifications
        • Android
        • iOS
        • Web
        • Flutter
      • Publishing to multiple devices
      • Publish to specific user
        • Android
        • iOS
        • Web
        • Flutter
      • Web push guides
        • Using an existing service worker
        • Web notification permissions in Firefox
        • Handling Safari certificate expiration
    • Reference
      • Client SDKs
        • Android
        • iOS
        • Web
      • All Libraries
      • Server SDKs
        • Go
        • PHP
        • Node.js
        • Python
        • Java/Kotlin
        • Ruby
        • Swift
      • API
        • Publish API
        • Customer API
        • Device API
        • Reporting API
        • Webhooks
      • Platform Publish Formats
    • Pusher lab

    PHP Server SDK

    This library requires a PHP version of 5.6 or greater

    ∞ Installation

    The Beams PHP Server SDK is available on Packagist here.

    We recommend that you use Composer to install this SDK.

    ∞ Using Composer

    You can add this SDK to your project using composer, or by directly adding it to your composer.json:

    composer require pusher/pusher-push-notifications
    "require": {
    "pusher/pusher-push-notifications": "^1.0"
    }

    ∞ Reference

    ∞ PushNotifications.__construct

    Constructs a new Beams client instance using your instance id and secret key (you can get these from the dashboard)

    ∞ Arguments

    ∞ $optionsArray Required
    • instanceId (String | required ): The unique identifier for your Push notifications instance. This can be found in the dashboard under “Credentials”.
    • secretKey (String | required ): The secret key your server will use to access your Beams instance. This can be found in the dashboard under “Credentials”.

    ∞ Example

    $beamsClient = new \Pusher\PushNotifications\PushNotifications(
    array(
    "instanceId" => "YOUR_INSTANCE_ID_HERE",
    "secretKey" => "YOUR_SECRET_KEY_HERE",
    )
    );

    ∞ .publishToInterests

    Sends broadcast notifications to groups of subscribed devices using Device Interests

    ∞ Arguments

    ∞ $interestsArray<string> Required

    Array of interests to send the push notification to, ranging from 1 to 100 per publish request. See Device Interests.

    ∞ $publishBody

    See publish API reference

    ∞ Returns

    An array containing the publish response body. See publish API reference

    ∞ Example

    <?php
    include 'src/PushNotifications.php';
    $publishResponse = $beamsClient->publishToInterests(
    array("hello", "donuts"),
    array(
    "fcm" => array(
    "notification" => array(
    "title" => "Hi!",
    "body" => "This is my first Push Notification!"
    )
    ),
    "apns" => array("aps" => array(
    "alert" => array(
    "title" => "Hi!",
    "body" => "This is my first Push Notification!"
    )
    )),
    "web" => array(
    "notification" => array(
    "title" => "Hi!",
    "body" => "This is my first Push Notification!"
    )
    )
    ));

    ∞ .publishToUsers

    Securely send notifications to individual users of your application using Authenticated Users

    ∞ Arguments

    ∞ $userIdsArray<string> Required

    Array of ids of users to send the push notification to, ranging from 1 to 1000 per publish request. See Authenticated Users.

    ∞ $publishBody

    See publish API reference

    ∞ Returns

    An array containing the publish response body. See publish API reference

    ∞ Example

    <?php
    include 'src/PushNotifications.php';
    $publishResponse = $beamsClient->publishToUsers(
    array("user-001", "user-002"),
    array(
    "fcm" => array(
    "notification" => array(
    "title" => "Hi!",
    "body" => "This is my first Push Notification!"
    )
    ),
    "apns" => array("aps" => array(
    "alert" => array(
    "title" => "Hi!",
    "body" => "This is my first Push Notification!"
    )
    )),
    "web" => array(
    "notification" => array(
    "title" => "Hi!",
    "body" => "This is my first Push Notification!"
    )
    )
    ));

    ∞ .generateToken

    Generate a Beams auth token to allow a user to associate their device with their user id. The token is valid for 24 hours.

    ∞ Arguments

    ∞ $userIdString Required

    Id of the user you would like to generate a Beams auth token for.

    ∞ Returns

    An array containing the token key.

    ∞ Example

    $userId = "user-001";
    $token = $beamsClient->generateToken($userId);
    // Return $token['token']; to device

    ∞ .deleteUser

    Remove the given user (and all of their devices) from Beams. This user will no longer receive any notifications and all state stored about their devices will be deleted.

    ∞ Arguments

    ∞ $userIdString Required

    Id of the user you would like to remove from Beams.

    ∞ Returns

    Nothing

    ∞ Example

    $beamsClient->deleteUser("user-001");

    Contents

    • Installation
      • Using Composer
    • Reference
      • PushNotifications.__construct
      • .publishToInterests
      • .publishToUsers
      • .generateToken
      • .deleteUser

    Spotted something that isn’t quite right? Create an issue on GitHub.

    Copyright © 2024 Pusher Ltd. All rights reserved.

    • Support,
    • Status
    • Follow Pusher on Twitter Twitter
    • Subscribe to Pusher’s channel on YouTube
    • Follow Pusher on LinkedIn
    • Follow Pusher on Github GitHub
    • Follow Pusher on Twitch Twitch
    • Follow Pusher on Discord Discord