Better Multisite Directories
| Project: | Drupal |
| Version: | 7.x-dev |
| Component: | base system |
| Category: | feature request |
| Priority: | normal |
| Assigned: | arnabdotorg |
| Status: | needs work |
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
comWhile 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
comProblems 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 "/").
| Attachment | Size |
|---|---|
| bootstrap.config.init.patch | 1.13 KB |

#1
+1, that seems pretty logical to me. I wasn't a fan of the exsiting method though.
#2
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?
#3
#4
#5
#6
#7
#8
I changed it as per comment #2 (chx)
#9
Is #231298: Aliased multi-site support perhaps related?
#10
The last submitted patch failed testing.