Admittedly, the reason is right, but what I would like to say today is another reason.
We know that PHP is going to determine whether a file is being loaded, it needs to get the file's Opened_path, meaning, for example:
Copy CodeThe code is as follows:
Set_include_path ("/tmp/:/tmp2/");
Include_once ("2.php");
?>
When PHP sees Include_once "2.php", he does not know what the actual path of the file is, and cannot tell whether it has been loaded from the list of loaded files, so in the implementation of Include_once, it will first attempt to parse the true path of the file ( For ordinary files This parsing is just like checking getcwd and file path, so if it is relative path, generally will not succeed), if the parse succeeds, then look for eg (include_files), if there is a description contained, return, otherwise open this file, Thus get the opened_path of this file. For example above, this file exists in "/tmp2/2.php".
Then, after getting this opened_path, PHP went to the list of loaded files to find, whether it has been included, if not included, then directly compile, no longer need open file.
1. Attempt to parse the absolute path of the file, if it can parse successfully, then check eg (included_files), the presence is returned, there is no continuation
2. Open the file to get the file open path (opened path)
3. Take opened path to the EG (included_files) lookup, whether it exists, returns if it exists, does not exist to continue
4. Compiling files (compile_file)
This is not a problem in most cases, but the problem is when you use APC ...
When using APC, APC hijacked the Compile_file this compiled file pointer, thus obtains the compilation result directly from the cache, avoids the open to the actual file, avoids to the open the system call.
However, when you use include_once in your code, before Compile_file, PHP has tried to open file before entering the compile file that was hijacked by APC, which results in an additional open operation. And APC is to solve this problem, introduced Include_once_override, in the case of Include_once_override Open, APC will hijack php zend_include_or_eval opcode Handler, by stat to determine the absolute path of the file, and then if the discovery is not loaded, rewrite opcode as include, do a tricky solution.
However, unfortunately, as I said, APC's include_once_override has been poorly implemented and there are some undefined issues, such as:
Copy CodeThe code is as follows:
Set_include_path ("/tmp");
function A ($arg = Array ()) {
Include_once ("b.php");
}
A ();
A ();
?>
Our b.php is then placed in "/tmp/b.php" with the following contents:
Copy CodeThe code is as follows:
Class B {}
?>
Then in the case of open apc.include_once_override, continuous access will get the following error:
Fatal error-include (): Cannot redeclare class
Excluding these technical factors, I have always believed that we should use the include, not include_once, because we can completely do our own planning, a file is only loaded once. You can also use auto-load to do this.
Your use of include_once can only prove that you have no confidence in your own code.
Therefore, we recommend that you do not use include_once
http://www.bkjia.com/PHPjc/328035.html www.bkjia.com true http://www.bkjia.com/PHPjc/328035.html techarticle It is true that the reason is right, but what I am going to say today is another reason. We know that PHP is going to determine if a file is being loaded and it is necessary to get this file Opened_pat ...