Wallogit.com
2017 © Pedro Peláez
Realplexor PHP API
Author: Inpassor inpassor@yandex.com, (*2)
GitHub repository: https://github.com/Inpassor/realplexor, (*3)
This library implements Dklab_Realplexor PHP API., (*4)
Dklab_Realplexor is comet server which handles 1000000+ parallel browser connections., (*5)
composer require inpassor/realplexor
Create some class which uses the trait RealplexorAPI:, (*6)
class Realplexor
{
use \inpassor\realplexor\RealplexorAPI;
...
}
Create the instance of this class (which uses the trait RealplexorAPI):, (*7)
$realplexor = new Realplexor(); $realplexor->host = '127.0.0.1'; $realplexor->port = 10010; $realplexor->namespace = 'rpl_';
Then use it:, (*8)
$realplexor->send('Alpha',$someData);
| Property | Type | Description |
|---|---|---|
| host | string | The server host. Default: '127.0.0.1' |
| port | integer | The connection port. Default: 10010 |
| namespace | string | Namespace to use. Default: '' |
| login | string | Login for connection (if the server need it). Default: '' |
| password | string | Password for connection (if the server need it). Default: '' |
| timeout | integer | The connection timeout, in seconds. Default: 5 |
| charset | integer | Charset used in Content-Type for JSON and other responses. Default: 'UTF-8' |
| lastError | string | Last error message, if error occured. |
| Method | Description |
|---|---|
| send() | Send data to Realplexor. |
| cmdOnlineWithCounters() | Return list of online IDs (keys) and number of online browsers for each ID ("online" means "connected just now", it is very approximate). |
| cmdOnline() | Return list of online IDs. |
| cmdWatch() | Return all Realplexor events (e.g. ID offline/offline changes) happened after $fromPos cursor. |
| Method | Description |
|---|---|
| _addNamespace() | Add the namespace to ID prefixes. |
| _cutNamespace() | Cut off the namespace from ID. |
| _sendCmd() | Send IN command. |
| _send() | Send specified data to IN channel. Return response data. |
Send data to Realplexor., (*9)
| Parameter | Type | Description |
|---|---|---|
| $idsAndCursors | mixed | Target IDs in form of: [id1 => cursor1, id2 => cursor2, ...] or [id1, id2, id3, ...]. If sending to a single ID, you may pass it as a plain string, not array. |
| $data | mixed | Data to be sent (any format, e.g. nested arrays are OK). |
| $showOnlyForIds | array | Send this message to only those who also listen any of these IDs. This parameter may be used to limit the visibility to a closed number of cliens: give each client an unique ID and enumerate client IDs in $showOnlyForIds to not to send messages to others. |
| return | boolean | True on success, false on fail. Check $this->lastError for error message if false returned. |
Return list of online IDs (keys) and number of online browsers for each ID ("online" means "connected just now", it is very approximate)., (*10)
| Parameter | Type | Description |
|---|---|---|
| $idPrefixes | string\ | array | If set, only online IDs with these prefixes are returned. |
| return | array | List of matched online IDs (keys) and online counters (values). Check $this->lastError for error message if empty array returned. |
Return list of online IDs., (*11)
| Parameter | Type | Description |
|---|---|---|
| $idPrefixes | string\ | array | If set, only online IDs with these prefixes are returned. |
| return | array | List of matched online IDs. Check $this->lastError for error message if empty array returned. |
Return all Realplexor events (e.g. ID offline/offline changes) happened after $fromPos cursor., (*12)
| Parameter | Type | Description |
|---|---|---|
| $fromPos | string | Start watching from this cursor. |
| $idPrefixes | string\ | array | Watch only changes of IDs with these prefixes. |
| return | array | List of ["event" => ..., "cursor" => ..., "id" => ...]. Check $this->lastError for error message if empty array returned. |
Add the namespace to ID prefixes., (*13)
| Parameter | Type | Description |
|---|---|---|
| $idPrefixes | string\ | array | ID prefixes without namespace. |
| return | string | ID prefixes with namespace. |
Cut off the namespace from ID., (*14)
| Parameter | Type | Description |
|---|---|---|
| $id | string | ID with namespace. |
| return | string | ID without namespace. |
Send IN command., (*15)
| Parameter | Type | Description |
|---|---|---|
| $cmd | string | Command to send. |
| return | string\ | null | Server IN response. Check $this->lastError for error message if null returned. |
Send specified data to IN channel. Return response data., (*16)
| Parameter | Type | Description |
|---|---|---|
| $identifier | string | If set, pass this identifier string. |
| $body | string | Data to be sent. |
| return | string\ | null | Response from IN line. Check $this->lastError for error message if null returned. |
To implement Realplexor client-side feel free to use bower package inpassor-jquery-realplexor, (*17)