|
|
|
@ -18,7 +18,6 @@ class Session |
|
|
|
public $registered; |
|
|
|
public $started; |
|
|
|
|
|
|
|
protected $buffer; |
|
|
|
private $state; |
|
|
|
|
|
|
|
private $verbose; |
|
|
|
@ -29,8 +28,8 @@ class Session |
|
|
|
private $language; |
|
|
|
private $offset; |
|
|
|
|
|
|
|
public function __construct($loop, $sid, $context, $baseuri, $language = false, |
|
|
|
$offset = 0, $verbose = false, $debug = false) |
|
|
|
public function __construct($loop, $sid, $context, $baseuri, |
|
|
|
$language = false, $offset = 0, $verbose = false, $debug = false) |
|
|
|
{ |
|
|
|
$this->sid = $sid; |
|
|
|
$this->baseuri = $baseuri; |
|
|
|
@ -40,10 +39,8 @@ class Session |
|
|
|
$this->verbose = $verbose; |
|
|
|
$this->debug = $debug; |
|
|
|
|
|
|
|
$this->context = $context; |
|
|
|
|
|
|
|
$this->clients = new \SplObjectStorage; |
|
|
|
$this->register($loop, $this); |
|
|
|
$this->register($loop, $this, $context); |
|
|
|
|
|
|
|
$this->timestamp = time(); |
|
|
|
} |
|
|
|
@ -84,21 +81,22 @@ class Session |
|
|
|
return $this->clients->count(); |
|
|
|
} |
|
|
|
|
|
|
|
private function register($loop, $me) |
|
|
|
private function register($loop, $me, $context) |
|
|
|
{ |
|
|
|
$buffer = ''; |
|
|
|
echo 'begin ' . shell_exec('ls /proc/'.getmypid().'/fd | wc -l'); |
|
|
|
$this->pullSocket = $context->getSocket(\ZMQ::SOCKET_PULL); |
|
|
|
$this->pushSocket = $context->getSocket(\ZMQ::SOCKET_PUSH); |
|
|
|
|
|
|
|
// Communication sockets with the linker
|
|
|
|
$file = CACHE_PATH . 'movim_feeds_' . $this->sid . '.ipc'; |
|
|
|
|
|
|
|
$this->pullSocket = $this->context->getSocket(\ZMQ::SOCKET_PULL); |
|
|
|
$this->pullSocket->getWrappedSocket()->setSockOpt(\ZMQ::SOCKOPT_LINGER, 0); |
|
|
|
echo 'pull ' . shell_exec('ls /proc/'.getmypid().'/fd | wc -l'); |
|
|
|
//$this->pullSocket->getWrappedSocket()->setSockOpt(\ZMQ::SOCKOPT_LINGER, 0);
|
|
|
|
$this->pullSocket->bind('ipc://' . $file . '_pull', true); |
|
|
|
|
|
|
|
$this->pushSocket = $this->context->getSocket(\ZMQ::SOCKET_PUSH); |
|
|
|
$this->pushSocket->getWrappedSocket()->setSockOpt(\ZMQ::SOCKOPT_LINGER, 0); |
|
|
|
var_dump(get_class($this->pullSocket)); |
|
|
|
echo 'push ' . shell_exec('ls /proc/'.getmypid().'/fd | wc -l'); |
|
|
|
//$this->pushSocket->getWrappedSocket()->setSockOpt(\ZMQ::SOCKOPT_LINGER, 0);
|
|
|
|
$this->pushSocket->bind('ipc://' . $file . '_push', true); |
|
|
|
|
|
|
|
echo 'pushbind ' . shell_exec('ls /proc/'.getmypid().'/fd | wc -l'); |
|
|
|
$this->pullSocket->on('message', function($msg) use ($me) { |
|
|
|
$me->messageOut($msg); |
|
|
|
}); |
|
|
|
@ -117,21 +115,28 @@ class Session |
|
|
|
] |
|
|
|
); |
|
|
|
$this->process->start($loop); |
|
|
|
|
|
|
|
echo 'al ' . shell_exec('ls /proc/'.getmypid().'/fd | wc -l'); |
|
|
|
// The linker died, we close properly the session
|
|
|
|
$this->process->on('exit', function($output) use ($me, $file) { |
|
|
|
$this->process->on('exit', function($output) use ($me, $file, $context) { |
|
|
|
if ($me->verbose) { |
|
|
|
echo colorize($this->sid, 'yellow'). " : ".colorize("linker killed \n", 'red'); |
|
|
|
} |
|
|
|
|
|
|
|
echo 'process end ' . shell_exec('ls /proc/'.getmypid().'/fd | wc -l'); |
|
|
|
$me->process = null; |
|
|
|
$me->closeAll(); |
|
|
|
|
|
|
|
$this->pullSocket->unbind('ipc://' . $file . '_pull'); |
|
|
|
$this->pushSocket->unbind('ipc://' . $file . '_push'); |
|
|
|
|
|
|
|
$this->pullSocket->close(); |
|
|
|
$this->pushSocket->close(); |
|
|
|
echo 'process clean ' . shell_exec('ls /proc/'.getmypid().'/fd | wc -l'); |
|
|
|
$me->pullSocket->unbind('ipc://' . $file . '_pull'); |
|
|
|
echo 'pull unbind ' . shell_exec('ls /proc/'.getmypid().'/fd | wc -l'); |
|
|
|
$me->pushSocket->unbind('ipc://' . $file . '_push'); |
|
|
|
echo 'push unbind ' . shell_exec('ls /proc/'.getmypid().'/fd | wc -l'); |
|
|
|
$me->pullSocket->close(); |
|
|
|
echo 'pull close ' . shell_exec('ls /proc/'.getmypid().'/fd | wc -l'); |
|
|
|
$me->pushSocket->close(); |
|
|
|
echo 'push close ' . shell_exec('ls /proc/'.getmypid().'/fd | wc -l'); |
|
|
|
unset($me->pullSocket); |
|
|
|
unset($me->pushSocket); |
|
|
|
unset($context); |
|
|
|
echo 'end ' . shell_exec('ls /proc/'.getmypid().'/fd | wc -l'); |
|
|
|
|
|
|
|
(new \Modl\PresenceDAO)->clearPresence(); |
|
|
|
(new \Modl\SessionxDAO)->delete($this->sid); |
|
|
|
|