Download the PHP package inpassor/realplexor without Composer
On this page you can find all versions of the php package inpassor/realplexor. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download inpassor/realplexor
More information about inpassor/realplexor
Files in inpassor/realplexor
Informations about the package realplexor
Realplexor PHP API
Author: Inpassor [email protected]
GitHub repository: https://github.com/Inpassor/realplexor
This library implements Dklab_Realplexor PHP API.
Dklab_Realplexor is comet server which handles 1000000+ parallel browser connections.
Installation
Usage
Create some class which uses the trait RealplexorAPI:
Create the instance of this class (which uses the trait RealplexorAPI):
Then use it:
Public Properties
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. |
Public methods
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. |
Protected methods
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. |
Method Details
public function send($idsAndCursors, $data, $showOnlyForIds = null)
Send data to Realplexor.
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. |
public function cmdOnlineWithCounters($idPrefixes = [])
Return list of online IDs (keys) and number of online browsers for each ID ("online" means "connected just now", it is very approximate).
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. |
public function cmdOnline($idPrefixes = [])
Return list of online IDs.
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. |
public function cmdWatch($fromPos, $idPrefixes = [])
Return all Realplexor events (e.g. ID offline/offline changes) happened after $fromPos cursor.
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. |
protected function _addNamespace($idPrefixes)
Add the namespace to ID prefixes.
Parameter | Type | Description |
---|---|---|
$idPrefixes | string|array | ID prefixes without namespace. |
return | string | ID prefixes with namespace. |
protected function _cutNamespace($id)
Cut off the namespace from ID.
Parameter | Type | Description |
---|---|---|
$id | string | ID with namespace. |
return | string | ID without namespace. |
protected function _sendCmd($cmd)
Send IN command.
Parameter | Type | Description |
---|---|---|
$cmd | string | Command to send. |
return | string|null | Server IN response. Check $this->lastError for error message if null returned. |
protected function _send($identifier, $body)
Send specified data to IN channel. Return response data.
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. |
Client-side
To implement Realplexor client-side feel free to use bower package inpassor-jquery-realplexor