pushradar/pushradar-php

This package is abandoned and no longer maintained. The author suggests using the pushradar/pushradar-server-php package instead.

PushRadar's official PHP library, wrapping the PushRadar API.

v2.0.9 2019-07-14 22:40 UTC

README

68747470733a2f2f7075736872616461722e73332d65752d776573742d322e616d617a6f6e6177732e636f6d2f76322f696d672f7075736872616461725f6769746875625f323032302e706e67

Build Status Latest Stable Version Total Downloads License

Introduction

PushRadar is a realtime API service for the web. The service uses a simple publish-subscribe model, allowing you to broadcast "messages" on "channels" that are subscribed to by one or more clients. Messages are pushed in realtime to those clients.

This is PushRadar's official PHP library.

Prerequisites

In order to use this library, please ensure that you have the following:

Composer

The easiest way to get up and running is to install the library using Composer. Run the following command in your console:

composer require pushradar/pushradar-php

To begin using the library, create an index.php file that loads Composer's autoloader from the /vendor folder:

require_once('vendor/autoload.php');

Manual Installation

Alternatively, if you do not wish to use Composer, you can download the latest release, and require_once the init.php file:

require_once('path/to/pushradar-php/init.php');

Dependencies

In order to use this library, please ensure you have enabled the following PHP extensions:

If you are using Composer, it will automatically check whether those extensions are enabled on your system.

Getting Started

"Hello World!" example:

$radar = new \PushRadar\PushRadar("your-secret-key");
$radar->broadcast("test-channel", array("message" => "Hello World!"));

Receiving Messages

To subscribe to channels and receive messages broadcast on them, check out the documentation for PushRadar's JavaScript client library.

Private Channels

Private channels require authentication before subscribers can receive messages on them.

To generate a channel authentication token, PushRadar provides a convenient channelAuth method that you can call from your authentication endpoint:

return response(json_encode(array("authToken" => $radar->channelAuth("channel-name"))));

Please note that private channels must start with the prefix 'private-'.

Encrypted Channels

PushRadar supports end-to-end encryption for channels. Encrypted channel names must start with the prefix 'private-encrypted-' and, like private channels, encrypted channels require authentication.

Your authentication endpoint should return a decryption key along with an authentication token as follows:

$radar->setEncryptionMasterKey("secret-master-passphrase");

return response(json_encode(array("authToken" => $radar->channelAuth("channel-name"), "decryptionKey" => $radar->generateDecryptionKey("channel-name"))));

The secret master passphrase you use should be long and hard to guess. Aim for at least 32 characters.

Documentation

Full documentation for PushRadar's PHP library can be found at: www.pushradar.com/docs/php.