summaryrefslogtreecommitdiff
path: root/plugins/Meteor/MeteorPlugin.php
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Meteor/MeteorPlugin.php')
-rw-r--r--plugins/Meteor/MeteorPlugin.php35
1 files changed, 32 insertions, 3 deletions
diff --git a/plugins/Meteor/MeteorPlugin.php b/plugins/Meteor/MeteorPlugin.php
index 5b345d7c2..ec8c9e217 100644
--- a/plugins/Meteor/MeteorPlugin.php
+++ b/plugins/Meteor/MeteorPlugin.php
@@ -50,6 +50,7 @@ class MeteorPlugin extends RealtimePlugin
public $controlport = null;
public $controlserver = null;
public $channelbase = null;
+ public $persistent = true;
protected $_socket = null;
function __construct($webserver=null, $webport=4670, $controlport=4671, $controlserver=null, $channelbase='')
@@ -65,6 +66,26 @@ class MeteorPlugin extends RealtimePlugin
parent::__construct();
}
+ /**
+ * Pull settings from config file/database if set.
+ */
+ function initialize()
+ {
+ $settings = array('webserver',
+ 'webport',
+ 'controlport',
+ 'controlserver',
+ 'channelbase');
+ foreach ($settings as $name) {
+ $val = common_config('meteor', $name);
+ if ($val !== false) {
+ $this->$name = $val;
+ }
+ }
+
+ return parent::initialize();
+ }
+
function _getScripts()
{
$scripts = parent::_getScripts();
@@ -82,8 +103,14 @@ class MeteorPlugin extends RealtimePlugin
function _connect()
{
$controlserver = (empty($this->controlserver)) ? $this->webserver : $this->controlserver;
+
+ $errno = $errstr = null;
+ $timeout = 5;
+ $flags = STREAM_CLIENT_CONNECT;
+ if ($this->persistent) $flags |= STREAM_CLIENT_PERSISTENT;
+
// May throw an exception.
- $this->_socket = stream_socket_client("tcp://{$controlserver}:{$this->controlport}");
+ $this->_socket = stream_socket_client("tcp://{$controlserver}:{$this->controlport}", $errno, $errstr, $timeout, $flags);
if (!$this->_socket) {
throw new Exception("Couldn't connect to {$controlserver} on {$this->controlport}");
}
@@ -104,8 +131,10 @@ class MeteorPlugin extends RealtimePlugin
function _disconnect()
{
- $cnt = fwrite($this->_socket, "QUIT\n");
- @fclose($this->_socket);
+ if (!$this->persistent) {
+ $cnt = fwrite($this->_socket, "QUIT\n");
+ @fclose($this->_socket);
+ }
}
// Meteord flips out with default '/' separator