The current system:

The current algorithm for looking for settings.php in the "sites" directory is:

1. Given a PATH(/path/to/file), and SERVERNAME(www.example.com:port)
2. Check SERVERNAME.PATH, replacing / with .
3. At every iteration, drop last part of PATH, and first part of SERVERNAME

So we have

port.www.example.com.path.to.file
www.example.com.path.to.file
example.com.path.to.file
com.path.to.file

("file" is removed)

port.www.example.com.path.to
www.example.com.path.to
example.com.path.to
com.path.to

("to" is removed)

port.www.example.com.path
www.example.com.path
example.com.path
com.path

("path" is removed)

port.www.example.com
www.example.com
example.com
com

While this heuristic is fairly usable, it has the following

Problems:

1. Loss of granularity: By dropping the rightmost elements, we lose the most important part of the information. For example, filesystem paths on large multiuser systems might be of the form /bighome/user/a/arnab/. Now there is no way to specify subdirectories unless we specify the WHOLE .bighome.user.a.arnab part. This can get very long and redundant with a large number of users. There's no way we can just use arnab or something as small as the directory name.

2. Clean URLs: I've encountered some servers, where using clean URLs produces a $_SERVER['PHP_SELF'] as /bighome/user/a/arnab/drupalA. However, when we use the ?q= methods to access these pages, this $_SERVER['PHP_SELF'] now becomes ~arnab/drupalA. Say I wanted to have two websites ~arnab/drupalA and ~arnab/drupalB, the current config_init does not let me do this, because I cannot set up an accessible directory pair like "drupalA" and "drupalB". I'll have to do "~arnab.drupalA" and "~arnab.drupalB". Now recall that during clean urls, this is "bighome.user.a.arnab.drupalA" instead! This makes it impossible to have consistency.

What this patch does:

Changes the logic so that the new algo is:

1. Given a PATH(/path/to/file), and SERVERNAME(www.example.com:port)
2. Check SERVERNAME.PATH, replacing / with .
3. At every iteration, first part of PATH, and first part of SERVERNAME

So we have

port.www.example.com.path.to.file
www.example.com.path.to.file
example.com.path.to.file
com.path.to.file

("path" is removed)

port.www.example.com.to.file
www.example.com.to.file
example.com.to.file
com.to.file

("to" is removed)

port.www.example.com.file
www.example.com.file
example.com.file
com.file


("file" is removed)

port.www.example.com
www.example.com
example.com
com

Problems with this patch:

1. This will break the current convention of moving "up" the filesystem path. However, the reason behind breaking this convention is because:
a) I don't see how multisite users can take advantage of this (would appreciate counter examples!)
b) code is more elegant without backward support logic

Advantages with this patch:

1. There are fewer array_implodes, array_pop & string concatenation is used to save redundant implode calls. This makes bootstrapping faster.
2. The ordering of the search is made so that the simpler (smaller) directory names are searched first. This is more intuitive, imho.
3. By changing the separator from "." to "/", and using a simple symlink like "com/bighome" -> "/bighome", we can allow each user to set up a settings.php in their homedir, giving them a drupal site automatically. This is not possible with the current set up, since there will be extra words in the path that would need to be removed inefficiently.
4. Many filesystems have a limit to the number of files in a directory. This allows us to have a more flexible directory / settings.php structure (assuming you use "/").

CommentFileSizeAuthor
#8 45938.patch1.35 KBroychri
bootstrap.config.init.patch1.13 KBarnabdotorg
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drewish’s picture

+1, that seems pretty logical to me. I wasn't a fan of the exsiting method though.

chx’s picture

Indeed there is some saving. For more savings, do a $n = count($server) outside of the loops.

As for the change, I am neutral. jhriggs? adrian? you two have written the original, what say you?

arnabdotorg’s picture

Priority: Normal » Critical
arnabdotorg’s picture

Category: feature » bug
moshe weitzman’s picture

Category: bug » feature
Priority: Critical » Normal
Jaza’s picture

Version: x.y.z » 6.x-dev
Status: Needs review » Needs work
catch’s picture

Version: 6.x-dev » 7.x-dev
roychri’s picture

Status: Needs work » Needs review
FileSize
1.35 KB

I changed it as per comment #2 (chx)

Crell’s picture

Anonymous’s picture

Status: Needs review » Needs work

The last submitted patch failed testing.

Jooblay.net’s picture

What is the status of this ticket:) Can we close this...

Jooblay.net’s picture

What is the status of this ticket:) Can we close this...