pushradar / pushradar-php
PushRadar's official PHP library, wrapping the PushRadar API.
Requires
- php: >=5.3.3
- ext-curl: *
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is auto-updated.
Last update: 2021-02-07 19:08:41 UTC
README
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:
- PHP 5.3.3 or later.
- A PushRadar account - you can sign up at www.pushradar.com.
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.