Settings.php and folder stucture

Hi everybody,

I have one question about folder structure.

Currently each page have the following:

require_once $_SERVER['DOCUMENT_ROOT'].'/settings.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/functions/main.php';
//logic code block goes here
require_once $_SERVER['DOCUMENT_ROOT'].'/includes/header.php';
//view code goes here
require_once $_SERVER['DOCUMENT_ROOT'].'/includes/footer.php';

The problem is I want to move settings outside root. I was thinking to put …/settings.php, but if I will later change settings.php location I will need to update each page.

So I was thinking to create extra require_once:

require_once $_SERVER['DOCUMENT_ROOT'].'/require_settings.php';

The script require_settings.php would have only 1 line:

require_once 'folderlocation/settings.php';

So if I change settings.php location next time, I only need to update require_settings.php. But this means for each script couple of sub require_once will be performed. Can be this bad?

That’s the joy of require_once(). You can do it as many times as you like, and it will only include the file the first time around!

So go wild!


require_once (and include_once) differs from require (and include) in that no matter how many times it’s included, it is only included once.

but I am not talking about including the same file. I am wondering how is about having sub require_once files.

So file A require_once file B, file B require_once file C and file C require_once file D. That is why I am asking if it is ok to put
require_once $_SERVER[‘DOCUMENT_ROOT’].‘/require_settings.php’;
where require_settings.php the only line will have is the following:

require_once 'folderlocation/settings.php';

The purpose of that is to change easily location of settings.php. But I am not sure if it is ok to have so many sub require_onces (due performance or other reason) because also settings.php require_once some files.

Well, each require (that isn’t skipped because of _once) does have a minor performance hit because it then has to do a disk read.

However, in this case if you are just putting “require settings” in one file, then having “require_once require_settings” in all the others, you should be fine because you are essentially only adding one additional file read.

Did that answer your question or am I missing something else?

I think yes, thank you :). A