I played around with my PHP script and as soon as I made a modification to an include, the execution time decreased 25%.
My old include was:
include_once "somefile.php";
My new one is:
include './somefile.php';
Because of this, I want to try to turn all my include_once's into includes and if I'm not careful, I could be including the same file twice unnecessarily.
I have files setup such that they represent what is shown below:
index2.php file: file user accesses:
<?php
//index2.php
include "../relative/path/to/includes/main.php";
anythingelse();
exit();
?>
index.php file: file user accesses:
<?php
//index.php
include "../relative/path/to/includes/main.php";
anything();
exit();
?>
core.php file: Loads every other file if not loaded so all functions work
<?php
include_once "../relative/path/to/includes/db.php";
include_once "../relative/path/to/includes/util.php";
include_once "../relative/path/to/includes/logs.php";
//core - main.php
function anything(){
initdb();
loaddb();
getsomething();
makealog();
}
function anythingelse(){
initdb();
loaddb();
getsomething();
getsomething();
makealog();
}
?>
db.php file: helper file
<?php
//database - db.php
function initdb(){
//initialize db
}
function loaddb(){
//load db
}
?>
util.php file: helper file
<?php
//utilities - util.php
function getsomething(){
//get something
}
?>
logs.php file: helper file
<?php
//logging - logs.php
function makealog(){
//generate a log
}
?>
The idea with my setup is the index.php and index2.php are the files users have direct access to. the core file is the root to all functionality as it loads the remaining php files containing the functions required for use by the core file which then in turn is used by the index.php and index2.php files.
As it stands, a solution to this would be for me to replace:
include_once "../relative/path/to/includes/db.php";
include_once "../relative/path/to/includes/util.php";
include_once "../relative/path/to/includes/logs.php";
with nothing and in index2.php and index.php, I add under the include, these lines:
include '/absolute/path/to/includes/db.php';
include '/absolute/path/to/includes/util.php';
include '/absolute/path/to/includes/logs.php';
The problem is, I have a few dozen files I have to do this to and I wanted to know if there is another way around this without merging all functions into one single file, because in reality, each PHP file I'm including contains at least 1,000 lines of code (and some lines contain at least 3 commands). I'm looking for a solution that results in lower execution time.