From 43d5989300820a443a32e07a203a1ac28e1eb1f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaussoin=20Timoth=C3=A9e?= Date: Wed, 18 Nov 2015 09:00:07 +0100 Subject: [PATCH] Do a first experiment related to #84 --- linker.php | 2 ++ src/Movim/Daemon/Core.php | 8 +++++--- src/Movim/Daemon/Session.php | 12 ++++++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/linker.php b/linker.php index 26ce04e6f..b934d1c6f 100644 --- a/linker.php +++ b/linker.php @@ -191,6 +191,8 @@ $xmpp_behaviour = function (React\Stream\Stream $stream) use (&$conn, $loop, &$s $obj = new \StdClass; $obj->func = 'registered'; + fwrite(STDERR, 'registered'); + //fwrite(STDERR, colorize(json_encode($obj).' '.strlen($obj), 'yellow')." : ".colorize('obj sent to browser', 'green')."\n"); echo base64_encode(gzcompress(json_encode($obj), 9)).""; diff --git a/src/Movim/Daemon/Core.php b/src/Movim/Daemon/Core.php index 212d458e7..8b27b872a 100644 --- a/src/Movim/Daemon/Core.php +++ b/src/Movim/Daemon/Core.php @@ -10,7 +10,7 @@ class Core implements MessageComponentInterface { public $loop; public $baseuri; - private $cleanerdelay = 24; // in hours + private $cleanerdelay = 12; // in hours public function __construct($loop, $baseuri, $port) { @@ -112,7 +112,9 @@ class Core implements MessageComponentInterface { { $this->loop->addPeriodicTimer(5, function() { foreach($this->sessions as $sid => $session) { - if(time()-$session->timestamp > $this->cleanerdelay*3600) { + if((time()-$session->timestamp > $this->cleanerdelay*3600) + || ($session->countClients() == 0 + && $session->registered == null)) { $session->killLinker(); $this->closeEmptySession($sid); } @@ -124,7 +126,7 @@ class Core implements MessageComponentInterface { { // No WebSockets and no linker ? We close the whole session if($this->sessions[$sid]->countClients() == 0 - && $this->sessions[$sid]->process == null) { + && ($this->sessions[$sid]->process == null)) { $sd = new \Modl\SessionxDAO(); $sd->delete($sid); diff --git a/src/Movim/Daemon/Session.php b/src/Movim/Daemon/Session.php index b3103d16b..5f183b54c 100644 --- a/src/Movim/Daemon/Session.php +++ b/src/Movim/Daemon/Session.php @@ -10,6 +10,8 @@ class Session { protected $baseuri; public $process; + public $registered; + protected $buffer; public function __construct($loop, $sid, $baseuri) @@ -77,9 +79,15 @@ class Session { $sd->delete($this->sid); }); + $self = $this; + // Debug only, if the linker output some errors - $this->process->stderr->on('data', function($output) use ($me) { - echo $output; + $this->process->stderr->on('data', function($output) use ($me, $self) { + if($output === 'registered') { + $self->registered = true; + } else { + echo $output; + } }); }