diff --git a/src/Engine/Engine.php b/src/Engine/Engine.php index a7ccf07..86bfb43 100644 --- a/src/Engine/Engine.php +++ b/src/Engine/Engine.php @@ -9,7 +9,7 @@ class Engine extends Emitter { public $pingTimeout = 60; public $pingInterval = 25; - public $upgradeTimeout = 10; + public $upgradeTimeout = 5; public $transports = array(); public $allowUpgrades = array(); public $allowRequest = array(); diff --git a/src/Engine/Socket.php b/src/Engine/Socket.php index 9a3ee87..267ab64 100644 --- a/src/Engine/Socket.php +++ b/src/Engine/Socket.php @@ -51,10 +51,11 @@ public function onUpgradePacket($packet) if('ping' === $packet['type'] && (isset($packet['data']) && 'probe' === $packet['data'])) { $this->upgradeTransport->send(array(array('type'=> 'pong', 'data'=> 'probe'))); + //$this->transport->shouldClose = function(){}; Timer::del($this->checkIntervalTimer); $this->checkIntervalTimer = Timer::add(0.1, array($this, 'check')); } - else if ('upgrade' === $packet['type'] && $this->readyState !== 'closed') + else if('upgrade' === $packet['type'] && $this->readyState !== 'closed') { $this->cleanup(); $this->upgraded = true; @@ -81,6 +82,7 @@ public function onUpgradePacket($packet) } + public function cleanup() { Timer::del($this->checkIntervalTimer); @@ -108,7 +110,7 @@ public function upgradeTimeoutCallback($transport) { echo("client did not complete upgrade - closing transport\n"); $this->cleanup(); - if('open' == $transport->readyState) + if('open' === $transport->readyState) { $transport->close(); } @@ -192,7 +194,13 @@ public function setPingTimeout() Timer::del($this->pingTimeoutTimer); $this->pingTimeoutTimer = Timer::add( $this->server->pingInterval + $this->server->pingTimeout , - array($this, 'onClose'), null, false); + array($this, 'pingTimeoutCallback'), null, false); + } + + public function pingTimeoutCallback() + { + $this->transport->close(); + $this->onClose('ping timeout'); } @@ -204,7 +212,7 @@ public function clearTransport() public function onClose($reason = '', $description = null) { - if ('closed' != $this->readyState) { + if ('closed' !== $this->readyState) { Timer::del($this->pingTimeoutTimer); Timer::del($this->checkIntervalTimer); $this->checkIntervalTimer = null; @@ -263,7 +271,7 @@ public function sendPacket($type, $data = null, $callback = null) public function flush() { - if ('closed' != $this->readyState && $this->transport->writable + if ('closed' !== $this->readyState && $this->transport->writable && $this->writeBuffer) { $this->emit('flush', $this->writeBuffer); @@ -296,7 +304,7 @@ public function getAvailableUpgrades() public function close() { - if ('open' != $this->readyState) + if ('open' !== $this->readyState) { return; } diff --git a/src/SocketIO.php b/src/SocketIO.php index 4dbf1a8..fcfb936 100644 --- a/src/SocketIO.php +++ b/src/SocketIO.php @@ -35,7 +35,7 @@ class_alias('PHPSocketIO\Engine\Protocols\SocketIO', 'Protocols\SocketIO'); public function path($v = null) { if($v === null) return $this->_path; - $this->_path = str_replace('/\/$/', '', $v); + $this->_path = preg_replace('/\/$/', '', $v); return $this; }