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": "^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

  • $options (array | required):
    • 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".

Example

Php

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

PushNotifications.publish

Sends broadcast notifications to groups of subscribed devices using Interests

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
An array containing the publish response body. See publish API reference

Example

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!"
      )
    ))
));

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.