I have read that when including a php file that using absolute paths has a faster processing time than relative paths.
What would you suggest to use?
include("includes/myscript.php");
or
include("/home/ftpuser/public_html/includes/myscript.php");
or even
set_include_path("/home/ftpuser/public_html/includes");
include("myscript.php");
Or is it something that I really shouldn't worry about?
I tend to setup my include directories / libraries by setting the include path on the initialisation of my app.
The zend framework does something similar to load the library classes.
I wrote a simple speed test script using
microtime(true)
. It tests the following five including methods with one million iterations:Which gave the following results (in seconds):
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
andset_include_path()
were used only once during execution of the script (they are located outside of the loop).