mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-29 16:55:05 +02:00
WS tick interval, WS manager able to limit connections per session
This commit is contained in:
parent
709f4cac81
commit
d34aa0917b
@ -130,6 +130,13 @@ class WSManager extends WebSocketServer
|
||||
*/
|
||||
public $handlerTick = [];
|
||||
|
||||
/**
|
||||
* Allow only one connection per user session.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $socketPerSession = false;
|
||||
|
||||
|
||||
/**
|
||||
* Builder.
|
||||
@ -292,8 +299,10 @@ class WSManager extends WebSocketServer
|
||||
);
|
||||
$this->stderr('ONLINE '.$user->address.'('.$user->account->idUser.')');
|
||||
|
||||
// Disconnect previous sessions.
|
||||
$this->cleanupSocketByCookie($user);
|
||||
if ($this->socketPerSession === true) {
|
||||
// Disconnect previous sessions.
|
||||
$this->cleanupSocketByCookie($user);
|
||||
}
|
||||
|
||||
// Launch registered handler.
|
||||
$this->callHandler(
|
||||
|
@ -164,6 +164,21 @@ abstract class WebSocketServer
|
||||
*/
|
||||
public $timeout = 1;
|
||||
|
||||
/**
|
||||
* Do not call tick every iteration, use a minimum time lapse.
|
||||
* Measure: seconds.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
public $tickInterval = 1;
|
||||
|
||||
/**
|
||||
* Last tick call. (unix timestamp).
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
public $lastTickTimestamp = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Builder.
|
||||
@ -420,7 +435,12 @@ abstract class WebSocketServer
|
||||
$except = null;
|
||||
$write = null;
|
||||
$this->pTick();
|
||||
$this->tick();
|
||||
|
||||
if ((time() - $this->lastTickTimestamp) > $this->tickInterval) {
|
||||
$this->lastTickTimestamp = time();
|
||||
$this->tick();
|
||||
}
|
||||
|
||||
socket_select($read, $write, $except, 0, $this->timeout);
|
||||
foreach ($read as $socket) {
|
||||
if ($socket == $this->master) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user