Under include_path, and then under include_path, where the current running script is located. For example, include_path Is ., the current working directory is/www/, and the script should include an include/. php Tutorial and include "B. php ", then look for B. the php sequence is/www/, and then/www/include /. If the file name starts with./or./, you can only search for it in the include_path Directory of the current working directory.
So the file structure is as follows:
---- A. php
---- Include/B. php
---- Include/c. php
A. php
<? Php
Include 'include/B. Php ';
?>
-----------------------
B. php
<? Php
Include 'C. Php ';
Include 'include/c. Php ';
?>
--------------------------
C. php
<? Php
Echo 'C. Php ';
?>
--------------------------
Both of them can run correctly, which means that the two different inclusion paths in B. php are feasible. You can find c. php in the method of searching for inclusion files based on include.
However, the best way is to use absolute paths. If absolute paths are used, the php kernel will directly load files through paths without having to include paths to search for files one by one, increasing the code execution efficiency.
<? Php
Define ('root _ path', dirname (_ file __));
Include root_path. '/c. Php ';
?>
Conclusion:
Obviously, the path format after include and the php include path have an impact on program performance. The sort of include performance from slow to fast is
Include 'A. Php' <include './a. Php' <include'/fullpath/a. php
In the code, using the absolute path include file is the best choice, because in this way, the php kernel directly loads files through the path instead of using the include path to search for files one by one.
So we 'd better define a constant for the absolute path of the project root directory in the public file of the project, and then carry this constant before all include paths, in this way, all the include operations in the project use absolute paths, which not only improves program performance, but also reduces the troubles caused by relative paths.
Reference Code (from emlog ):
Define ('emlog _ root', dirname (_ file __));
Include emlog_root. '/config. Php ';
If you have used a large number of relative paths in the include 'test. Php' format in your project and it is not easy to modify a large number of paths, try to reduce the paths in the php include path to improve the include performance. Because the fewer paths in include path, the less time php will spend searching for files.