function variable_initialize
7.x bootstrap.inc | variable_initialize($conf = array()) |
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()
- DrupalWebTestCase::refreshVariables in drupal-7.x/
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 drupal-7.x/
includes/ bootstrap.inc - Loads system variables and all enabled bootstrap modules.
File
- drupal-7.x/
includes/ bootstrap.inc, line 903 - 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_get('variables', 'cache_bootstrap')) {
$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_set('variables', $variables, 'cache_bootstrap');
lock_release($name);
}
}
foreach ($conf as $name => $value) {
$variables[$name] = $value;
}
return $variables;
}