public function ping($timeout = 10) { $payload = $this->pingSeq; $this->conn->send(new Frame($payload, true, Frame::OP_PING)); $seq = $this->pingSeq; $this->pingSeq++; if ($timeout > 0) { $timer = $this->loop->addTimer($timeout, function () use($seq) { if (isset($this->pingRequests[$seq])) { $this->pingRequests[$seq]['deferred']->reject('timeout'); unset($this->pingRequests[$seq]); } }); $deferred = new Deferred(); $this->pingRequests[$seq] = array('seq' => $seq, 'deferred' => $deferred, 'timer' => $timer); return $deferred->promise(); } }
protected function defaultExecute($type, array $msg, callable $onSuccess, callable $onError = null) { $comKey = rand(100000, 999999); $msg = json_encode(array_merge(['type' => $type, 'comKey' => $comKey], $this->defaultFields, $msg)); $this->verboseLog("MESSAGE SENT: {$msg}", 'comment'); $this->conn->send($msg); $this->callbacks[$comKey] = $onSuccess; if ($onError) { $this->errorCallbacks[$comKey] = $onError; } }
/** * close transport */ public function close() { $this->conn->close(); }