function conf_path

You are here

7 bootstrap.inc conf_path($require_settings = TRUE, $reset = FALSE)
4.7 bootstrap.inc conf_path()
5 bootstrap.inc conf_path()
6 bootstrap.inc conf_path($require_settings = TRUE, $reset = FALSE)
8 bootstrap.inc conf_path($require_settings = TRUE, $reset = FALSE)

Returns the appropriate configuration directory.

Returns the configuration path based on the site's hostname, port, and pathname. Uses find_conf_path() to find the current configuration directory. See default.settings.php for examples on how the URL is converted to a directory.

Parameters

bool $require_settings: Only configuration directories with an existing settings.php file will be recognized. Defaults to TRUE. During initial installation, this is set to FALSE so that Drupal can detect a matching directory, then create a new settings.php file in it.

bool $reset: Force a full search for matching directories even if one had been found previously. Defaults to FALSE.

Return value

The path of the matching directory.

See also

default.settings.php

24 calls to conf_path()
DatabaseTasks_sqlite::getFormOptions in includes/database/sqlite/install.inc
Return driver specific configuration options.
DrupalPublicStreamWrapper::getDirectoryPath in includes/stream_wrappers.inc
Implements abstract public function getDirectoryPath()
DrupalTestCase::run in modules/simpletest/drupal_web_test_case.php
Run all tests in this class.
DrupalUnitTestCase::setUp in modules/simpletest/drupal_web_test_case.php
Sets up unit test environment.
DrupalWebTestCase::drupalGetTestFiles in modules/simpletest/drupal_web_test_case.php
Get a list files that can be used in tests.

... See full list

3 string references to 'conf_path'
drupal_rewrite_settings in includes/install.inc
Replaces values in settings.php with values in the submitted array.
install_settings_form in includes/install.core.inc
Form constructor for a form to configure and rewrite settings.php.
install_verify_settings in includes/install.core.inc
Verifies the existing settings in settings.php.

File

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

Code

function conf_path($require_settings = TRUE, $reset = FALSE) {
  $conf = &drupal_static(__FUNCTION__, '');

  if ($conf && !$reset) {
    return $conf;
  }

  $confdir = 'sites';

  $sites = array();
  if (file_exists(DRUPAL_ROOT . '/' . $confdir . '/sites.php')) {
    // This will overwrite $sites with the desired mappings.
    include (DRUPAL_ROOT . '/' . $confdir . '/sites.php');
  }

  $uri = explode('/', $_SERVER['SCRIPT_NAME'] ? $_SERVER['SCRIPT_NAME'] : $_SERVER['SCRIPT_FILENAME']);
  $server = explode('.', implode('.', array_reverse(explode(':', rtrim($_SERVER['HTTP_HOST'], '.')))));
  for ($i = count($uri) - 1; $i > 0; $i--) {
    for ($j = count($server); $j > 0; $j--) {
      $dir = implode('.', array_slice($server, -$j)) . implode('.', array_slice($uri, 0, $i));
      if (isset($sites[$dir]) && file_exists(DRUPAL_ROOT . '/' . $confdir . '/' . $sites[$dir])) {
        $dir = $sites[$dir];
      }
      if (file_exists(DRUPAL_ROOT . '/' . $confdir . '/' . $dir . '/settings.php') || (!$require_settings && file_exists(DRUPAL_ROOT . '/' . $confdir . '/' . $dir))) {
        $conf = "$confdir/$dir";
        return $conf;
      }
    }
  }
  $conf = "$confdir/default";
  return $conf;
}

Comments

Instead of

<?php
 
for ($i = count($uri) - 1; $i > 0; $i--) {
  for (
$j = count($server); $j > 0; $j--) {
?>

it shoulda been

<?php
  $countUri
= count($uri) - 1; // or even sizeof($uri) - 1
 
for ($i = $countUri; $i > 0; $i--) {
   
$countServer = count($server); // or even sizeof($server) - 1
   
for ($j = $countServer; $j > 0; $j--) {
?>

May speed up the loop up to 500 times! Look at the benchmarks in the "Counting Loops" section (all the way on the bottom)
http://www.phpbench.com/

I also noticed this in other functions, but this is maybe not the full list.
- _locale_import_one_string
- _locale_import_parse_arithmetic
- drupal_html_to_text
- xmlrpc_value

@ultrabutter
please, try to submit a patch to the HEAD.
http://drupal.org/node/add/project-issue/drupal

The patch can be tested and reviewed by the community and hopefully ... committed to the core.

There is no advantage to pre-calculating the initial value of the loop variable, as that is evaluated only once.

The advantage is in pre-calculating the final value used in the test expression, as that is evaluated during each iteration of the loop.

To illustrate:

  1. for ($i = complex_function(); $i > 0; $i--) {

  2. $start = complex_function();
    for ($i = $start; $i > 0; $i--) {

#1 and #2 should run at nearly identical speed. If anything, #1 should be (very) slightly faster as it contains one less assignment.

  1. for ($i = 0; $i < complex_function(); $i++){

  2. $finish = complex_function();
    for ($i = 0; $i < $finish; $i++) {

#1 should be much slower, as it evaluates complex_expression() on every iteration of the loop, whereas #2 only evaluates it once.

I have to say that although the difference might be minuscule (in most cases), I think you're right. I set up my own local test based on the code I from the link you provided and I was somewhat surprised at the difference that's made when count()</count> is pre-calculated instead of being placed directly into the <code>for loops.

I also noticed this comment is a couple years old and no one has submitted a patch yet (unless I missed it), so I'll go ahead and submit one right now.

Here's the code I used for the tests:

<?php
/**
* Set up variables
*/
global $x;
$i = 0;
$tmp = '';
while (
$i < 10000) {
 
$tmp .= 'a';
  ++
$i;
}
$x = array_fill(5, 1000, $tmp);
unset(
$i, $tmp);

/**
* Benchmark test with precalculated count
*/
function benchmark_with_precalculation() {
  global
$x;
 
$t = microtime(true);
 
$size = count($x);
  for (
$i = 0; $i < $size; $i++);
  return (
microtime(true) - $t);
}

/**
* Benchmark test without precalculated count
*/
function benchmark_sans_precalculation() {
  global
$x;
 
$t = microtime(true);
  for (
$i = 0; $i < count($x); $i++);
  return (
microtime(true) - $t);
}

/**
* Reset variables for next test
*/
function benchmark_reset() {
  global
$x;
  unset(
$x);
}

/**
* The actual test
*/
function benchmark_do_benchmark() {
 
benchmark_reset();
 
$results_n = 'Execution time (precalculated = N): ';
 
$results_n .= benchmark_sans_precalculation();
 
benchmark_reset();
 
$results_y = 'Execution time (precalculated = Y): ';
 
$results_y .= benchmark_with_precalculation();
 
benchmark_reset();
  return
$results_n . '<br/>' . $results_y;
}

/**
* Print test results
*/
print benchmark_do_benchmark();
?>