Browse Source

Do a first experiment related to #84

pull/90/head
Jaussoin Timothée 10 years ago
parent
commit
43d5989300
  1. 2
      linker.php
  2. 8
      src/Movim/Daemon/Core.php
  3. 10
      src/Movim/Daemon/Session.php

2
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))."";

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

10
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) {
$this->process->stderr->on('data', function($output) use ($me, $self) {
if($output === 'registered') {
$self->registered = true;
} else {
echo $output;
}
});
}

Loading…
Cancel
Save