Пример #1
0
 protected function __construct()
 {
     $this->enabled = extension_loaded('mysql') && Config::getInstance()->enabled;
     if ($this->enabled) {
         $this->setUpDatabase();
         $this->setData('config', \ManiaLive\Config\Config::getInstance());
         $this->setData('wsapi', \ManiaLive\Features\WebServices\Config::getInstance());
         $this->setData('manialive', \ManiaLive\Application\Config::getInstance());
         $this->setData('server', \ManiaLive\DedicatedApi\Config::getInstance());
         $this->setData('threading', \ManiaLive\Threading\Config::getInstance());
     } else {
         Logger::debug('Application started with threading disabled!', true, array('Process #' . getmypid()));
         $this->buffers[0] = array();
     }
     Dispatcher::register(TickEvent::getClass(), $this);
 }
Пример #2
0
 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;
         }
     }
 }
Пример #3
0
 private function handleTimeOuts()
 {
     foreach ($this->lastTick as $threadId => $tick) {
         if (empty($this->pendings[$threadId]) && $this->tick - $tick > Config::getInstance()->busyTimeout / 2) {
             $threadStatus = proc_get_status($this->threads[$threadId]);
             if ($threadStatus['running']) {
                 $this->lastTick[$threadId] = $this->tick;
             } else {
                 $this->restartThread($threadId);
             }
         } else {
             if ($this->tick - $tick > Config::getInstance()->busyTimeout) {
                 $this->restartThread($threadId);
             }
         }
     }
 }