public function addConnection(Connection $connection) { if (!isset($this->connections[$connection->getId()])) { $this->connections[$connection->getId()] = $connection; } return $this; }
/** * Registers the socket with a new Connection object and stores that * @param resource The socket for the new client */ private function connect($clientSocket) { $connection = new Connection($clientSocket); $this->connections[$connection->getId()] = $connection; $this->sockets[$connection->getId()] = $clientSocket; //we throw a new event to handle new connections $onConnectingEvent = new \System\Web\Websocket\Event\OnConnectingEvent(); $onConnectingEvent->setServer($this); $onConnectingEvent->setConnection($connection); $onConnectingEvent->raise(); }
/** * NOT idempotent, call once per data * * @param Connection $connection */ protected function checkRequestsPerMinute($connection) { $id = $connection->getId(); if (!isset($this->requests[$id])) { $this->requests[$id] = array(); } // Add current token $this->requests[$id][] = time(); // Expire old tokens while (reset($this->requests[$id]) < time() - 60) { array_shift($this->requests[$id]); } if (count($this->requests[$id]) > $this->options['requests_per_minute']) { $this->limit($connection, 'Requests per minute'); } }
public function addConnection(Connection $connection) { $this->connections[$connection->getId()] = $connection; }
public function remove(Connection $connection) { unset($this->connections[$connection->getId()]); }