I wrote a simple speed test script using microtime(true)
. It tests the following five including methods with one million iterations:
// Absolute path.
include( /home/ftpuser/public_html/includes/myscript.php );
// Predefined path.
define( PATH , /home/ftpuser/public_html/includes/ );
include(PATH . myscript.php );
// Relative path.
include( myscript.php );
// Using set_include_path().
set_include_path( /home/ftpuser/public_html/includes/ );
include( myscript.php );
// Superglobal path.
include(dirname(__FILE__) . /myscript.php );
Which gave the following results (in seconds):
Absolute path: 263.222
Predefined path: 263.545
Relative path: 301.214
Using set_include_path(): 302.396
Superglobal path: 269.631
My opinion based on these results is to use a predefined path, because it s the fastest only surpassed by an absolute path. However, an absolute path has the drawback that it must be altered in every file when a change is necessary.
Hope this helped. :)
P.S.
define
and set_include_path()
were used only once during execution of the script (they are located outside of the loop).