/**
  * Refresh the data cache
  *
  * @return void
  */
 static function refreshDataCache()
 {
     $mutex = new CMbFileMutex("config-build");
     $mutex->acquire(20);
     // If cache was built by another thread
     if (self::getValuesCacheStatus() === self::STATUS_OK) {
         $mutex->release();
         $hosts_shm = SHM::get("config-values-__HOSTS__");
         $hosts = $hosts_shm["content"];
         $values = array();
         foreach ($hosts as $_host) {
             $_host_value = SHM::get("config-values-{$_host}");
             $values[$_host] = $_host_value["content"];
         }
         self::$values = $values;
         self::$hosts = $hosts;
         self::$dirty = false;
         mbLog("'config-values' already present, skipping regeneration");
         return;
     }
     $t = microtime(true);
     self::buildAllConfig();
     $t1 = microtime(true) - $t;
     $datetime = strftime(CMbDT::ISO_DATETIME);
     foreach (self::$values as $_host => $_configs) {
         SHM::put("config-values-{$_host}", array("date" => $datetime, "content" => $_configs));
     }
     SHM::put("config-values-__HOSTS__", array("date" => $datetime, "content" => array_keys(self::$values)));
     $t2 = microtime(true) - $t - $t1;
     mbLog(sprintf("'config-values' gerenated in %f ms, written in %f ms", $t1 * 1000, $t2 * 1000));
     $mutex->release();
     self::$dirty = false;
 }
 /**
  * @see parent::read()
  */
 function read($session_id)
 {
     $client = self::$client;
     $this->lock_name = "session_{$session_id}";
     $this->lifetime = ini_get('session.gc_maxlifetime');
     // Init the right mutex type
     $mutex = new CMbFileMutex($this->lock_name);
     $mutex->acquire($this->lock_timeout);
     $this->mutex = $mutex;
     $key = $this->getKey($session_id);
     if (!$client->has($key)) {
         return "";
     }
     $session = $client->get($key);
     if ($session) {
         $session = unserialize($session);
         $data = $session['data'];
         $this->data_hash = md5($data);
         return $data;
     }
     return "";
 }
Exemplo n.º 3
0
 /**
  * Load locales from cache or build the cache
  *
  * @return void
  */
 public static function loadLocales()
 {
     $lang = CAppUI::pref("LOCALE", "fr");
     self::$lang = $lang;
     $shared_name = "locales-{$lang}";
     $locales_prefixes = SHM::get("{$shared_name}-" . self::LOCALES_PREFIX);
     // Load from shared memory if possible
     if ($locales_prefixes) {
         return;
     }
     $mutex = new CMbFileMutex("locales-build");
     $mutex->acquire(5);
     $locales_prefixes = SHM::get("{$shared_name}-" . self::LOCALES_PREFIX);
     // Load from shared memory if possible
     if ($locales_prefixes) {
         $mutex->release();
         return;
     }
     $locales = array();
     foreach (self::getLocaleFilesPaths($lang) as $_path) {
         include_once $_path;
     }
     $locales = CMbString::filterEmpty($locales);
     foreach ($locales as &$_locale) {
         $_locale = CMbString::unslash($_locale);
     }
     unset($_locale);
     // Load overwritten locales if the table exists
     $overwrite = new CTranslationOverwrite();
     if ($overwrite->isInstalled()) {
         $locales = $overwrite->transformLocales($locales, $lang);
     }
     // Prefix = everything before "." and "-"
     $by_prefix = array();
     $hashes = array();
     foreach ($locales as $_key => $_value) {
         /** @var string $_prefix */
         /** @var string $_rest */
         /** @var string $_prefix_raw */
         list($_prefix, $_rest, $_prefix_raw) = self::splitLocale($_key);
         if (!isset($by_prefix[$_prefix])) {
             $hashes[$_prefix] = $_prefix_raw;
             $by_prefix[$_prefix] = array();
         }
         $by_prefix[$_prefix][$_rest] = $_value;
     }
     foreach ($by_prefix as $_prefix => $_locales) {
         self::$locales[$_prefix] = $_locales;
         self::$locales_loaded[$_prefix] = true;
         SHM::put("{$shared_name}-{$_prefix}", $_locales);
     }
     SHM::put("{$shared_name}-" . self::LOCALES_PREFIX, $hashes);
     $mutex->release();
 }