PHP include file contains a summary of the path search problem

Source: Internet
Author: User

First, let's look at the description of the file search principles for include in the official PHP manual:

Files for including is first looked for with each include_path entry relative to the current working directory, and then in The directory of current script. e.g. if your include_path is libraries, current working directory  are, you included and  there are include "b.php" C2/>in that file, was first looked in and so in  . If filename begins with./  or. /, it is looked with the current working directory.

The order in which to find the included files is looked for in the relative include_path of the current working directory, and then include_path under the current directory where the script is currently running. For example Include_path is . , the current working directory is, the script to include one and in the file has an include "b.php" , then the order of the search is first, then. If the file name is. / or : / Start, search only under the include_path of the current working directory.

So the file structure as shown below

----a.php

----include/b.php

----include/c.php

where a.php

<?phpinclude ' include/b.php ';? >-----------------------b.php<?phpinclude ' c.php ', include ' include/c.php ';? >

--------------------------

c.php

<?phpecho ' c.php ';? >

--------------------------

Can be run correctly, indicating that two different include paths in b.php are feasible, and c.php can be found in the way that include searches for included files.

But the best way is to use absolute path, if the absolute path is used, the PHP kernel directly through the path to load the file without going to include path to search for files, increase the efficiency of code execution

<?phpdefine (' Root_path ', DirName (FILE)); include Root_path. ' /c.php ';? >

Different file inclusion methods, the execution performance of the program can be compared to the specific reference to this article

<script type= "Text/javascript" ><!--google_ad_client = " ca-pub-1944176156128447 ";/* cnblogs home Banner */google_ad_slot =" 5419468456 "; google_ad_width = 728;google_ad_height = 90;// --></script><script type= "Text/javascript" src= "</SCRIPT> 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.