function variable_initialize

Loads the persistent variable table.

The variable table is composed of values that have been saved in the table with variable_set() as well as those explicitly specified in the configuration file.

2 calls to variable_initialize()
WebTestBase::refreshVariables in drupal/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
Refresh the in-memory set of variables. Useful after a page request is made that changes a variable in a different thread.
_drupal_bootstrap_variables in drupal/core/includes/bootstrap.inc
Loads system variables and all enabled bootstrap modules.

File

drupal/core/includes/bootstrap.inc, line 966
Functions that need to be loaded on every Drupal request.

Code

function variable_initialize($conf = array()) {

  // NOTE: caching the variables improves performance by 20% when serving
  // cached pages.
  if ($cached = cache('bootstrap')
    ->get('variables')) {
    $variables = $cached->data;
  }
  else {

    // Cache miss. Avoid a stampede.
    $name = 'variable_init';
    if (!lock()
      ->acquire($name, 1)) {

      // Another request is building the variable cache.
      // Wait, then re-run this function.
      lock()
        ->wait($name);
      return variable_initialize($conf);
    }
    else {

      // Proceed with variable rebuild.
      $variables = array_map('unserialize', db_query('SELECT name, value FROM {variable}')
        ->fetchAllKeyed());
      cache('bootstrap')
        ->set('variables', $variables);
      lock()
        ->release($name);
    }
  }
  foreach ($conf as $name => $value) {
    $variables[$name] = $value;
  }
  return $variables;
}