PHP Server SDK

Installation

The Beams PHP Server SDK is available on Packagist here.

We recommend that you use Composer to install this SDK.

Install Using Composer

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

1
$ composer require pusher/pusher-push-notifications

JSON

1
2
3
"require": {
    "pusher/pusher-push-notifications": "^0.10"
}

Installing Without a Package Manager

If you would like to add the SDK to your project yourself you can download the source code from github

1
$ git clone https://github.com/pusher/push-notifications-php/

Usage

Connecting to Pusher

Use your instance id and secret key (you can get these from the dashboard) to create a Beams instance:

PHP

1
2
3
4
$pushNotifications = new \Pusher\PushNotifications\PushNotifications(array(
  "instanceId" => "YOUR_INSTANCE_ID_HERE",
  "secretKey" => "YOUR_SECRET_KEY_HERE",
));

Publishing a Push Notification

Once you have connected to Pusher you can publish a push notification to your registered & subscribed devices:

PHP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
include 'src/PushNotifications.php';
$publishResponse = $pushNotifications->publish(
  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!"
      )
    ))
));

Reference

Pusher\Pushnotifications::PushNotifications

__construct(array $options)

Construct a new Pusher Beams Client connected to your Beams instance.

Arguments
$options:

  • instanceId(string | required): The unique identifier for your Push notifications instance. This can be found in the dashboard under "keys".
  • secretKey(string | required): The secret key your server will use to access your Beams instance. This can be found in the dashboard under "keys".

array publish(array $publishBody)

Publish a new push notification to Pusher Beams with the given payload.

Arguments
$interests (Array<string> | required): Array of interests to send the push notification to, ranging from 1 to 100 per publish request. See Interests.
$publishBody: See publish API reference

Returns
$publishResponse: See publish API reference

Did you find this document useful?

We are always striving to create the most accurate and informative docs as possible. If there is something especially wrong (or right) here then please let us know.