function onLoad() { parent::onLoad(); $config = ManagerConfig::getInstance(); $this->db = \ManiaLive\Database\Connection::getConnection($config->host, $config->username, $config->password, $config->database, $config->type, $config->port); $status = $this->connection->getStatus(); $quotedHost = $this->db->quote(Config::getInstance()->host); $quotedLogin = $this->db->quote($this->storage->serverLogin); $quotedPassword = $this->db->quote(Config::getInstance()->password); $quotedStatus = $this->db->quote($status->name); $this->db->execute('INSERT INTO Servers (hostname, port, login, superAdminPassword, status) ' . 'VALUES (%s,%d,%s,%s,%s) ' . 'ON DUPLICATE KEY UPDATE login = VALUES(login), ' . 'superAdminPassword = VALUES(superAdminPassword), ' . 'status = VALUES(status)', $quotedHost, Config::getInstance()->port, $quotedLogin, $quotedPassword, $quotedStatus); $this->enableDedicatedEvents(); $this->enableApplicationEvents(); $this->enableTickerEvent(); }
private function setUpDatabase() { $dbConfig = \ManiaLive\Database\Config::getInstance(); $this->database = Connection::getConnection($dbConfig->host, $dbConfig->username, $dbConfig->password, $dbConfig->database, 'MySQL', $dbConfig->port); $this->database->execute('CREATE TABLE IF NOT EXISTS `ThreadingProcesses` (' . '`parentId` INT(10) UNSIGNED NOT NULL,' . '`lastLive` DATETIME NOT NULL,' . 'PRIMARY KEY (`parentId`)' . ')' . 'COLLATE=\'utf8_general_ci\''); $this->database->execute('CREATE TABLE IF NOT EXISTS `ThreadingData` (' . '`parentId` INT(10) UNSIGNED NOT NULL,' . '`name` VARCHAR(255) NOT NULL,' . '`value` TEXT NOT NULL,' . 'PRIMARY KEY (`parentId`, `name`)' . ')' . 'COLLATE=\'utf8_general_ci\''); $this->database->execute('CREATE TABLE IF NOT EXISTS `ThreadingCommands` (' . '`parentId` INT(10) UNSIGNED NOT NULL,' . '`commandId` INT(10) UNSIGNED NOT NULL,' . '`threadId` INT(10) UNSIGNED NOT NULL,' . '`task` TEXT NOT NULL,' . '`result` TEXT NULL DEFAULT NULL,' . '`timeTaken` FLOAT UNSIGNED NULL DEFAULT NULL,' . 'PRIMARY KEY (`parentId`, `commandId`),' . 'INDEX `threadId` (`threadId`)' . ')' . 'COLLATE=\'utf8_general_ci\''); $deadPids = $this->database->execute('SELECT parentId FROM ThreadingProcesses WHERE parentId=%d OR DATE_ADD(lastLive, INTERVAL 2 MINUTE) < NOW()', getmypid())->fetchArrayOfSingleValues(); if ($deadPids) { $deadPids = implode(',', array_map('intval', $deadPids)); $this->database->execute('DELETE FROM ThreadingProcesses WHERE parentId IN (%s)', $deadPids); $this->database->execute('DELETE FROM ThreadingData WHERE parentId IN (%s)', $deadPids); $this->database->execute('DELETE FROM ThreadingCommands WHERE parentId IN (%s)', $deadPids); } $this->database->execute('INSERT INTO ThreadingProcesses(parentId, lastLive) VALUES(%s, NOW())', getmypid()); }
private function initDatabase() { $options = getopt(null, array('dbHost::', 'dbPort::', 'dbUsername::', 'dbPassword::', 'dbDatabase::')); $dbConfig = \ManiaLive\Database\Config::getInstance(); foreach ($options as $key => $value) { $dbConfig->{lcfirst(substr($key, 2))} = $value; } $this->database = Connection::getConnection($dbConfig->host, $dbConfig->username, $dbConfig->password, $dbConfig->database, 'MySQL', $dbConfig->port); // load configs from DB $configs = array('config' => \ManiaLive\Config\Config::getInstance(), 'wsapi' => \ManiaLive\Features\WebServices\Config::getInstance(), 'manialive' => \ManiaLive\Application\Config::getInstance(), 'server' => \ManiaLive\DedicatedApi\Config::getInstance(), 'threading' => Config::getInstance()); foreach ($configs as $dbName => $instance) { $data = $this->getData($dbName, array()); foreach ((array) $data as $key => $value) { $instance->{$key} = $value; } } }
function onDraw() { // statistics for memory usage $memory = memory_get_usage(); $text = '$oPHP Memory$z' . "\n" . 'Current Memory Usage: ' . round($memory / 1024) . " kb\n" . 'Total Peak Memory: ' . round(memory_get_peak_usage() / 1024) . " kb\n" . 'PHP Memory Limit: ' . round($this->memoryLimit / 1024) . " kb\n" . 'Amount Used: ' . round(100 * $memory / $this->memoryLimit, 2) . "%\n" . '$oPHP Speed$z' . "\n"; if (empty($this->cpuStats)) { $text .= '$iRetrieving information...$z' . "\n"; } else { $text .= 'Current Cycles per Second: ' . end($this->cpuStats) . "\n" . 'Avg Reaction Time: ' . round(1000 * count($this->cpuStats) / (array_sum($this->cpuStats) ?: 1)) . " msecs\n"; } // manialive specific stats $text .= '$oManiaLive$z' . "\n"; // runtime $diff = time() - \ManiaLive\Application\AbstractApplication::$startTime; $seconds = $diff % 60; $minutes = floor($diff % 3600 / 60); $hours = floor($diff % 86400 / 3600); $days = floor($diff / 86400); $text .= "ManiaLive Uptime:\n{$days} days and {$hours} hours\n{$minutes} min and {$seconds} seconds\n"; // threading $text .= '$oThreading$z' . "\n"; $processHandler = ThreadHandler::getInstance(); if ($processHandler->isEnabled()) { $text .= 'Enabled; Running:' . $processHandler->countThreads() . '; Restarted:' . $processHandler->countRestartedThreads() . "\n" . $processHandler->countFinishedCommands() . ' commands finished at avg ' . round($processHandler->getAverageResponseTime(), 3) . ' ms'; } else { $text .= "Disabled\n"; } // update left side of the page $this->leftLabel->setText($text); // database $text = '$oDatabase$z' . "\n"; $times = Connection::getMeasuredAverageTimes(); if (count($times)) { $i = 0; foreach ($times as $time) { $text .= 'Connection #' . ++$i . ":\n" . 'Avg Query Time: ' . round($time, 3) . ' sec' . "\n"; } } else { $text .= "No Database connections running.\n"; } // network $text .= '$oNetwork$z' . "\n" . 'Total Bytes Sent: ' . round(Client::$sent / 1024) . "kb\n" . 'Total Bytes Received: ' . round(Client::$received / 1024) . "kb\n" . '$oInterface Drawing$z' . "\n" . 'Avg Drawing Time: ' . round(GuiHandler::getInstance()->getAverageSendingTimes() * 1000) . " msec\n" . '$oPlugins$z' . "\n" . 'Currently loaded: ' . count(PluginHandler::getInstance()->getLoadedPluginsList()); // update right side of the page $this->rightLabel->setText($text); }
protected final function enableDatabase() { $config = \ManiaLive\Database\Config::getInstance(); $this->db = DbConnection::getConnection($config->host, $config->username, $config->password, $config->database, $config->type, $config->port); }