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.

3 calls to variable_initialize()
DrupalWebTestCase::refreshVariables in modules/simpletest/drupal_web_test_case.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 includes/bootstrap.inc
Loads system variables and all enabled bootstrap modules.
_menu_check_rebuild in includes/menu.inc
Checks whether a menu_rebuild() is necessary.

File

includes/bootstrap.inc, line 1238

Code

function variable_initialize($conf = array()) {
    // NOTE: caching the variables improves performance by 20% when serving
    // cached pages.
    if ($cached = cache_get('variables', 'cache_bootstrap')) {
        $variables = $cached->data;
    }
    else {
        // Cache miss. Avoid a stampede by acquiring a lock. If the lock fails to
        // acquire, optionally just continue with uncached processing.
        $name = 'variable_init';
        $lock_acquired = lock_acquire($name, 1);
        if (!$lock_acquired && variable_get('variable_initialize_wait_for_lock', FALSE)) {
            lock_wait($name);
            return variable_initialize($conf);
        }
        else {
            // Load the variables from the table.
            $variables = array_map('unserialize', db_query('SELECT name, value FROM {variable}')->fetchAllKeyed());
            if ($lock_acquired) {
                cache_set('variables', $variables, 'cache_bootstrap');
                lock_release($name);
            }
        }
    }
    foreach ($conf as $name => $value) {
        $variables[$name] = $value;
    }
    return $variables;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.