Meteor realtime plugin: use persistent connections by default when pushing updates from our queue threads

This commit is contained in:
Brion Vibber 2010-06-03 17:41:26 -07:00
parent 5f4c6ec626
commit a75095fa1a

View File

@ -50,6 +50,7 @@ class MeteorPlugin extends RealtimePlugin
public $controlport = null; public $controlport = null;
public $controlserver = null; public $controlserver = null;
public $channelbase = null; public $channelbase = null;
public $persistent = true;
protected $_socket = null; protected $_socket = null;
function __construct($webserver=null, $webport=4670, $controlport=4671, $controlserver=null, $channelbase='') function __construct($webserver=null, $webport=4670, $controlport=4671, $controlserver=null, $channelbase='')
@ -102,8 +103,14 @@ class MeteorPlugin extends RealtimePlugin
function _connect() function _connect()
{ {
$controlserver = (empty($this->controlserver)) ? $this->webserver : $this->controlserver; $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. // 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) { if (!$this->_socket) {
throw new Exception("Couldn't connect to {$controlserver} on {$this->controlport}"); throw new Exception("Couldn't connect to {$controlserver} on {$this->controlport}");
} }
@ -124,8 +131,10 @@ class MeteorPlugin extends RealtimePlugin
function _disconnect() function _disconnect()
{ {
$cnt = fwrite($this->_socket, "QUIT\n"); if (!$this->persistent) {
@fclose($this->_socket); $cnt = fwrite($this->_socket, "QUIT\n");
@fclose($this->_socket);
}
} }
// Meteord flips out with default '/' separator // Meteord flips out with default '/' separator