The current OPCache cannot get rid of the source file to execute the opcode file. The path will allow OPCache direct execution opcode file without php source code file.
This function is similar to java, python, .net etc. performing bytecode functions. However, the existing execution and operation mechanism of PHP is not changed.
Copy use opcache_compile_file() function complie result file to special path. then prepend flag (<?phpo) and php_version_id to copy of file.
When executing, judge whether the loaded PHP file is an opcode file based on the flag. if no flag, will run as it is now.If is opcode file will direct execution without check php source file.
The includes() includes_once() and require() require_one() can load opcode file. So if you include opcode files, the source code must use the compiled file path instead of the source file path.
Change function to:
opcache_compile_file(string $file, string $opcode_file = null): bool
1. current process:
[php-load-source] ---> [compile to opcode] ---> [store to cache system directory]
2. path change to process:
[php-load-source] ---> [compile to opcode] ---> [save to cache system directory] ---> [copy cache file to the specified path]
3. When specified path, the opcode file format change to like below:
<?phpo{phpversionid}OPCACHE575d367cc725713f6f170910d6e9ee5e-------BINARY CONTENT OF OPCODE----
The above code explains:
1. current opcache exec process:
[php] ---> [find cache in cache system directory] --->x---> [found] -->[exec opcode] \---> [not found] ---> [exec php source]
2. path added process:
PHP's constant is similar to a C macro,their values are determined when compiled into opcode. Therefore, the value of the system-related constant depends on the compiler's system environment. So magic constant __FILE__ is set to the absolute path of the compiler's php source file, instead of the absolute path of the opcode file when executed. __DIR__ and __LINE__ also have this problem. Therefore, applications that rely on these constants are affected.
The file path obtained by error reporting, exceptions, reflections, will also be the path to the compiled file, not the current opcode file path.
PHP 8.x
None.
not support direct execution opcode file in phar.
Opcache can direct execution opcode file without php source file. When direct execution opcode file, will remove verify accel_system_id and validate_timestamps. Other is compatible.
None.
If there are any php.ini settings then list:
Voting opens 2021-04-05 and 2021-04-20 at 00:00:00 UTC. 2/3 required to accept.