Closed (works as designed)
Project:
Drupal core
Version:
10.1.x-dev
Component:
configuration system
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Anonymous (not verified)
Created:
17 Jul 2015 at 14:12 UTC
Updated:
1 Feb 2023 at 21:33 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
joyceg commentedComment #2
cilefen commentedNo, it would overwrite only the settings.default.php not settings.php. I do not agree with this issue. Just as many (if not more) sites don't need this and it will be expensive for them.
Comment #3
joyceg commentedSo,is this issue invalid?
Comment #4
cilefen commentedI am just one opinion. Incidentally, it went in with #1118520: Add inclusion of a settings.local.php file in settings.php.
Comment #5
cilefen commentedComment #6
cilefen commentedI feel this is an advanced configuration for those that know what they are doing so it should be commented out.
Comment #7
wim leerssettings.phpshould never be committed to the VCS, so is not a convincing reason I'm afraid :).file_exists() in the condition that encapsulates the inclusion of that file is very inexpensive so it would not impact performance.— this is not true, any file system hit (any I/O, really) is very expensive.So I'm afraid all of these things are really done intentionally, after very careful consideration.
settings.phpandsettings.local.phpare never intended to leave a specific machine. They're not intended to be shared. If you want to share a bunch of settings that aren't machine-specific, create asettings.something.phpfile and commit that, and have each machine'ssettings.phpinclude that.Comment #8
misc commentedIn our deploy process we build the site every time, and we also sometimes use the settings.local.php - therefor we need the lines to be uncommented. I don't really see the case here for having them commented at all - if the settings.local.php exists it should be included.
No need to have the lines commented out as I see it.
Anyway, I am re-opening this ticket, and adding a small patch.
Comment #10
deadbeef commentedThis is a major issue on any non-trivial application which may be installed and tested across many different environments in a development lifecycle. Certain configuration will always be infrastructure-dependent , and having to manipulate settings.php in every instance is painful. Aegir, for example writes settings.php itself and includes a facility like this.
file_exists() is cached in the statcache, and has absolutely negligible performance impact.
Comment #11
dawehnerLet's quote https://secure.php.net/manual/en/function.clearstatcache.php
The actual performance problem though would result into having less caching enabled by default.
Comment #12
fabianx commentedIIRC there is a possibility to run a hook after settings.php is written, so a distribution could decide to unconditionally load a settings.local.php file e.g.
This is a decision of fast-by-default. By default Drupal puts e.g. mysql data directly in settings.php, so a settings.local.php is not needed.
If you need it in your workflow, just commit a 'default-settings' settings.php to GIT or add a distribution specific hook.
However as 90% of sites will never need a settings.local.php, giving them an unnecessary I/O hit, would be good to avoid.
Comment #13
misc commentedIf this should be a performance issue - could someone point out a test that shows that this really is a performance issue? I can not see how one file_exists could have any impact on the application as a whole.
A none existing file should not have any impact on caching - it's just a FALSE on a response.
And, there are a bunch of `file_exists()` in core already.
Comment #14
wim leersThe difference is that this
file_exists()would run for every request (even for page cache hits).I think @catch and others have nice linkable anecdotes of the problems of ?
Comment #15
misc commentedOff course it depends on what you have in the file you include if you use
file_exists(). But a none existing file should have zero measurable impact on a application at the size of Drupal 8.Testing locally (I know that not the best place to test, but better there than nowhere ;-)), I am getting no differences in performance if the file exists or not.
Comment #16
wim leersThat's because your local webserver is not a multi-head webserver. Once you use multiple webservers, you need them to be in sync. That means a shared file system. Try using NFS or Gluster. Then it will be very noticeable.
It can also be a problem on a single server (think shared hosting) when the HDD/SSD is in heavy use and even doing that single
file_exists()call can take many milliseconds.Comment #17
misc commentedI know that it is different environments. But the function itself should have none measurable impact on a drupal 8 site. But for fairs sake, I will try to get some live-testing up just for fun, I will come back with some results. If we have not tested the case, it seems strange, from my point of view, to assume that this minor thing would have an overall impact.
Comment #18
wim leersIt has been measured, time and time again, and this is why Drupal 8 doesn't have any
file_exists()calls in the critical path.Comment #19
misc commentedOk, could you point me to the testing on this for Drupal 8 - I must have missed it.
Comment #20
dawehnerLet's use tools for that:
$ git log --all --grep="file_exists"points to #752730: Remove file_exists() during bootstrap which has an straceand a blog entry: #752730-11: Remove file_exists() during bootstrap #752730-13: Remove file_exists() during bootstrap
Comment #21
misc commentedI can not see the relevancy here? We are talking about one
file_exist()- that should not have the impact that is raised in #752730. Or am I missing something obvious?Comment #22
richard.c.allen2386 commentedI tend to agree with MiSc here. I think Wim Leers use case is much less represented than the use case of a small team working on projects trying manage configuration. I think it would be just as easy to say that a team dealing with NFS could just comment that line settings.php.
I'd prefer the flexibility of having it uncommented by default. Yes it would require changes and education but overall I would prefer it this way and I know others would as well.
As for performance, from what I can see on most sites we are talking very trival performance issues. It's not like we don't include an .htaccess though by default when apache very clearly states "You should avoid using .htaccess files completely if you have access to httpd main server config file. Using .htaccess files slows down your Apache http server. Any directive that you can include in a .htaccess file is better set in a Directory block, as it will have the same effect with better performance." Yeah it's slower but it's easier to work with and helps folks when learning.
Having it uncommented by default and having an install option to install to settings.php or local.settings.php should be included in my opinion.
Comment #25
misc commentedUpdated patch
Comment #27
kyvour commentedI'm agree with MiSc. For now settings.php contains two kinds of settings:
1) settings that can (and probably should) be same on different environments. For example CONFIG_SYNC_DIRECTORY, update_free_access, file_chmod_directory, file_chmod_file, public and private files path etc. Also different contrib modules like "fast 404" might require own settings in this file.
2) settings that can/should be different on different environments. Usually these are settings that are added to the file during the drupal installation: $databases array, hash_salt, install_profile.
On my opinion, drupal should have 2 fies with settings - settings.php and settings.local.php (or probably will be better to rename it to settings.env.php). In this case 1st kind of settings can be included to VCS. And new installation of site's instance will have all required configuration from the beginning. Also in this case result of file_exists() will be cached (or even this condition will be unnecessary)
But this solution requires some updates for installation process, because now settings always will be added to the settings.php file during the drupal installation.
Comment #28
Anonymous (not verified) commentedJust FYI Drupal does a shitload of file operations on twig tempaltes alone, not even looking at the whole code base here. And one file_exists/is_readable is a laughable argument here.
Comment #32
misc commentedUpdated patch - I still see no valid reasons raised here to have this commented out.
Comment #35
matthieuscarset commented+1 for uncommenting the
file_exists()too.Comment #42
catchIf you run file_exists() against a non-existing file, there is no caching from PHP at all - the filesystem will check whether the file exists on every single request to Drupal, because it can never guarantee that it's not just been written. See the docs on https://www.php.net/manual/en/function.clearstatcache.php
How bad this is probably depends on the individual file system, but since settings.php is loaded for the internal page cache, even a small change can have a measurable impact on those pages.
Also since this issue was created, sites are built with composer which includes scaffolding for settings.php, so it's a lot easier to manage stuff like this in git.
Marking this works as designed.