2017 © Pedro Peláez
 

library realplexor

Realplexor PHP API

image

inpassor/realplexor

Realplexor PHP API

  • Thursday, October 20, 2016
  • by Inpassor
  • Repository
  • 1 Watchers
  • 1 Stars
  • 79 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 36 % Grown

The README.md

Realplexor PHP API

Latest Stable Version Total Downloads License, (*1)

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)

Installation

composer require inpassor/realplexor

Usage

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

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., (*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.

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)., (*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.

public function cmdOnline($idPrefixes = [])

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.

public function cmdWatch($fromPos, $idPrefixes = [])

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.

protected function _addNamespace($idPrefixes)

Add the namespace to ID prefixes., (*13)

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., (*14)

Parameter Type Description
$id string ID with namespace.
return string ID without namespace.

protected function _sendCmd($cmd)

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.

protected function _send($identifier, $body)

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.

Client-side

To implement Realplexor client-side feel free to use bower package inpassor-jquery-realplexor, (*17)

The Versions

20/10 2016

dev-master

9999999-dev

Realplexor PHP API

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Avatar Inpassor

long polling comet realplexor dklab_realplexor

20/10 2016

0.1.2

0.1.2.0

Realplexor PHP API

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Avatar Inpassor

long polling comet realplexor dklab_realplexor