public function onUpdate() { $mem = new \Jamm\Memory\RedisObject('messages'); $messages = $mem->read(self::MSG_CONTAINER); if (!empty($messages)) { $newMessages = []; foreach ($messages as $msg) { if (!array_key_exists($msg->userId, $this->users)) { $newMessages[] = $msg; continue; } foreach ($this->users[$msg->userId] as $user) { if ($user[self::CLIENT_KEY]->getSocket()->isConnected()) { $user[self::CLIENT_KEY]->send(json_encode($msg->toArray())); } } } $mem->del(self::MSG_CONTAINER); $mem->save(self::MSG_CONTAINER, $newMessages); } }