/**
  * Removes a client and all references in case of timeout/error.
  * @param object $client The client object to remove.
  */
 public function removeClientOnError($client)
 {
     // remove reference in clients app:
     if (method_exists($this->_hook, 'onDisconnect')) {
         $this->_hook->onDisconnect((int) $client->getClientSocket());
     }
     $resource = $client->getClientSocket();
     $clientId = $client->getClientId();
     $clientIp = $client->getClientIp();
     $clientPort = $client->getClientPort();
     $this->_removeIpFromStorage($client->getClientIp());
     if (isset($this->_requestStorage[$clientId])) {
         unset($this->_requestStorage[$clientId]);
     }
     unset($this->clients[(int) $resource]);
     $index = array_search($resource, $this->allsockets);
     unset($this->allsockets[$index], $client);
     // trigger status application:
     if ($this->getApplication('status') !== false) {
         $this->getApplication('status')->clientDisconnected($clientIp, $clientPort);
     }
     unset($resource, $clientId, $clientIp, $clientPort);
 }
 /**
  *	Only Valids, with client
  *
  *	@param	object	$query
  *	@param	object	$client
  *
  *	@return	object
  */
 public function scopeValidWithClient($query, $client)
 {
     return $query->where('client_id', $client->getClientId())->whereRaw('expires > now()');
 }