4.7.x bootstrap.inc conf_path()
5.x bootstrap.inc conf_path()
6.x bootstrap.inc conf_path($require_settings = TRUE, $reset = FALSE)
7.x 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. See default.settings.php for examples on how the URL is converted to a directory.


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


22 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.


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


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';
  $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;


ultrabutter’s picture

Instead of

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

it shoulda been

  $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)

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

jpsoto’s picture

please, try to submit a patch to the HEAD.

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

pillarsdotnet’s picture

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.

jerdiggity’s picture

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:

 * Set up variables
global $x;
$i = 0;
$tmp = '';
while ($i ' . $results_y;

 * Print test results
print benchmark_do_benchmark();

jonhattan’s picture

chOP’s picture

For Drupal 8.x see DrupalKernel::getSitePath