====== PHP RFC: Direct execution opcode file without php source code file ====== * Version: 0.1 * Date: 2020-11-13 * Author: chopins xiao(chopins.xiao@gmail.com) * Status: Declined * First Published at: http://wiki.php.net/rfc/direct-execution-opcode ===== Introduction ===== 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. ===== Proposal ===== Copy use **opcache_compile_file()** function complie result file to special path. then prepend flag (** opcache_compile_file(string $file, string $opcode_file = null): bool ==== Implement a schematic flowchart ==== === The PHP source code file is compiled into an opcode file flowchart: === 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: **The above code explains:** - ** [php] ---> [find cache in cache system directory] --->x---> [found] -->[exec opcode] \---> [not found] ---> [exec php source] 2. path added process: [php/phpo] --->x---> [is phpo] ---> [load the phpo file] ---> [exec opcode] \--->[not phpo] ---> [find cache in cache system directory] --->x---> [found] ---> [exec opcode] \---> [not found] ---> [exec php source] ---> [auto cache opcode] ===== Backward Incompatible Changes ===== 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. ===== Proposed PHP Version ===== PHP 8.x ===== RFC Impact ===== ==== To SAPIs ==== None. ==== To Existing Extensions ==== not support direct execution opcode file in phar. ==== To Opcache ==== 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. ==== New Constants ==== None. ==== php.ini Defaults ==== If there are any php.ini settings then list: * opcache.allow_direct_exec_opcode * if set 0, default value, same as the current state, can not direct exec any opcode file * if set 1, only when opcode file start is ** * Yes * No ===== Patches and Tests ===== [[https://github.com/php/php-src/pull/6146]] ===== Implementation ===== [[https://github.com/php/php-src/pull/6146/commits/75fbf645c431f1afbcc4418ddda86f5afec98853|75fbf645c431f1afbcc4418ddda86f5afec98853]] ===== References ===== - [[https://externals.io/message/111965|Main thread]] - [[https://externals.io/message/112482|About magic constant]]