protected function assertNotificationPacket($uid, Notification $obj) { // there is a hack, check database directly, notification key 'N_' . $uid // message send maybe need some times, so wait for a second sleep(2); $packetStr = Cache::getInstance()->lPop('N_' . $uid); self::assertTrue($packetStr && false !== strpos($packetStr, $obj->content['type'])); }
<?php require __DIR__ . '/../../src/bootstrap.php'; $config = (require __DIR__ . '/../../examples/web-chat-system/config/server.php'); \jegarn\cache\Cache::getInstance()->initConfig($config['cache']);
public function start() { if (!$this->running) { $ssl = isset($this->config['ssl_cert_file']) && $this->config['ssl_cert_file']; $server = new swoole_server($this->config['host'], $this->config['port'], SWOOLE_PROCESS, $ssl ? SWOOLE_SOCK_TCP | SWOOLE_SSL : SWOOLE_SOCK_TCP); $server->set($this->config); $server->on('connect', [$this, 'onSwooleConnect']); $server->on('receive', [$this, 'onSwooleReceive']); $server->on('close', [$this, 'onSwooleClose']); $server->on('PipeMessage', [$this, 'onSwoolePipeMessage']); $this->register(); $this->instance =& $server; Cache::getInstance()->preventProcessShare(); $this->running = true; $this->instance->start(); } }
public function _initServer() { Cache::getInstance()->initConfig(\Yaf\Application::app()->getConfig()->get('application')->get('cache')); Server::getInstance()->initConfig(\Yaf\Application::app()->getConfig()->get('application')->get('chat'))->register(); }
/** * @param $sessionId * @return Session|null * @throws \Exception */ public function getSessionBySessionId($sessionId) { if ($sessionId && ($sessionStr = Cache::getInstance()->get($this->getSessionIdCacheKey($sessionId)))) { if (($foundSession = ConvertUtil::unpack($sessionStr)) && $foundSession instanceof Session) { return $foundSession; } } return null; }
public function getMessageCount($uid) { Cache::getInstance()->lSize($this->getCacheKey($uid)); }
public function removeUser($account) { Cache::getInstance()->del($this->getCacheKey($account)); }
private function modifyServerInfo() { $bindServerId = 'l_' . $this->config['host'] . ':' . $this->config['port']; $cache = Cache::getInstance(); $cache->hSet($bindServerId, 'connect', $this->connectCount); $cache->hSet($bindServerId, 'receive', $this->receiveCount); $cache->hSet($bindServerId, 'send', $this->sendCount); $cache->hSet($bindServerId, 'close', $this->closeCount); $cache->hSet($bindServerId, 'error', $this->errorCount); $cache->hSet($bindServerId, 'memory', memory_get_peak_usage(true)); $this->lastFlushTime = time(); }
/** * return the user number of remove out of group * @param integer $gid * @param array $uidList * @throws \Exception */ public function removeGroupUsers($gid, $uidList) { array_unshift($uidList, $this->getCacheKey($gid)); call_user_func_array([Cache::getInstance(), 'sRem'], $uidList); }
<?php use jegarn\cache\Cache; use minions\db\Db; define('PIC_HOST', '/upload/'); define('TEST_HOST', 'http://192.168.199.243'); require __DIR__ . '/../../examples/web-chat-system/src/bootstrap.php'; require __DIR__ . '/../../sdk/php/src/jegarn.php'; require __DIR__ . '/AppTestBase.php'; $config = new \Yaf\Config\Ini(__DIR__ . '/../../examples/web-chat-system/config/application.ini', 'develop'); Db::getInstance()->initConfig($config->get('application')->get('database')); Cache::getInstance()->initConfig($config->get('application')->get('cache'));