You are here

function httprl_variable_get in HTTP Parallel Request & Threading Library 7

Same name and namespace in other branches
  1. 6 httprl.module \httprl_variable_get()

Returns a persistent variable.

This version will read directly from the database if value is not in global $conf variable.

Case-sensitivity of the variable_* functions depends on the database collation used. To avoid problems, always use lower case for persistent variable names.

Parameters

string $name: The name of the variable to return.

mixed $default: The default value to use if this variable has never been set.

Return value

mixed The value of the variable.

See also

variable_del()

variable_set()

17 calls to httprl_variable_get()
httprl_acquire_headless_lock in ./httprl.module
Get a floating lock so background calls work.
httprl_acquire_lock in ./httprl.module
Get a lock so background calls work.
httprl_build_url_self in ./httprl.module
Helper function to build an URL for asynchronous requests to self.
httprl_drupal_get_private_key in ./httprl.module
Gets the private key variable.
httprl_install_fclose_delay_check in ./httprl.install

... See full list

File

./httprl.module, line 3010
HTTP Parallel Request Library module.

Code

function httprl_variable_get($name, $default = NULL) {

  // Try global configuration variable first.
  global $conf;
  if (isset($conf[$name])) {
    return $conf[$name];
  }

  // Try database next if not at a full bootstrap level.
  if (function_exists('db_query') && !httprl_drupal_full_bootstrap()) {
    if (defined('VERSION') && substr(VERSION, 0, 1) >= 7) {
      $variables = array_map('unserialize', db_query('SELECT name, value FROM {variable} WHERE name = :name', array(
        ':name' => $name,
      ))
        ->fetchAllKeyed());

      // Use the default if need be.
      return isset($variables[$name]) ? $variables[$name] : $default;
    }
    else {
      $result = db_query("SELECT value FROM {variable} WHERE name = '%s'", $name);
      if (!empty($result)) {
        $result = db_result($result);
        if (!empty($result)) {
          $value = @unserialize($result);
        }
      }

      // Use the default if need be.
      return isset($value) ? $value : $default;
    }
  }
  else {

    // Return default if database is not available or if at a full bootstrap.
    return $default;
  }
}