rfc:direct-execution-opcode

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:direct-execution-opcode [2020/12/10 12:33] chopinsrfc:direct-execution-opcode [2021/04/23 18:07] (current) – Deadline has passed. RFC is declined. imsop
Line 3: Line 3:
   * Date: 2020-11-13   * Date: 2020-11-13
   * Author: chopins xiao(chopins.xiao@gmail.com)   * Author: chopins xiao(chopins.xiao@gmail.com)
-  * Status: Draft+  * Status: Declined
   * First Published at: http://wiki.php.net/rfc/direct-execution-opcode   * First Published at: http://wiki.php.net/rfc/direct-execution-opcode
  
 ===== Introduction ===== ===== Introduction =====
-Allow php direct execution opcode file without php source file.+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 ===== ===== Proposal =====
Line 21: Line 23:
 </PHP> </PHP>
  
-==== Implementation Method====+==== Implement a schematic flowchart ====
  
-**compile to file:**+=== The PHP source code file is compiled into an opcode file flowchart===
  
-1. current opcache store to file:+1. current process: 
 +<PHP> 
 +[php-load-source] ---> [compile to opcode] --->  [store to cache system directory] 
 +</PHP>
  
-php**--->**load code**--->**compile to opcode **--->**store to cache system directory**-->**same path file+2. path change to process: 
 +<PHP> 
 +[php-load-source] ---> [compile to opcode---> [save to cache system directory] ---> [copy cache file to the specified path] 
 +</PHP>
  
-2. path added optional: +3When specified paththe opcode file format change to like below:
- +
-php--->load code--->compile to opcode--->save to cache system directory-->same path file-->**copy cache file to the specified path** +
- +
-new opcode file format like below:+
  
 <PHP> <PHP>
Line 39: Line 43:
 </PHP> </PHP>
  
-**opcache exec process:**+**The above code explains:** 
 +   - **<?phpo**:   is opcode file flag. when specified compile to file prepend 
 +   - **{phpversionid}**:   is current php version id. when specified compile to file prepend 
 +   - **OPCACHE575d367cc725713f6f170910d6e9ee5e**:  opcode file magic info and systemid. it's not change. 
 +   - **-------BINARY CONTENT OF OPCODE----**:  opcode data, it's not change 
 + 
 +=== OPCache extentsion exec flowchart: ===
  
-1. current opcache exec:+1. current opcache exec process:
 <PHP> <PHP>
-[php]-->[find cache in cache system directory]-->[found] -->[exec opcode] +[php] ---> [find cache in cache system directory] --->x---> [found] -->[exec opcode] 
-                                                   \--->[not found]--> [exec php source]+                                                       \---> [not found] ---> [exec php source]
 </PHP> </PHP>
  
-2. path added optional:+2. path added process:
 <PHP> <PHP>
-[php/phpo]--->[is phpo, <?phpo exist]--->[load the <?phpo file] ---->[exec opcode] +[php/phpo] --->x---> [is phpo] ---> [load the phpo file] ---> [exec opcode] 
-          \---->[not phpo] ---> [find cache in cache system directory]-->[found] -->[exec opcode] +               \--->[not phpo] ---> [find cache in cache system directory] --->x---> [found] ---> [exec opcode] 
-                                                   \------------>[not found] --> [exec php source]-->[auto cache opcode]+                                                                                \---> [not found] ---> [exec php source] ---> [auto cache opcode]
 </PHP> </PHP>
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
-Magic constant **%%__FILE__%%** is the absolute path to the compiled source file, not the path to the opcode file that is currently executing. **%%__DIR__%%** and **%%__LINE__%%** also have this problem. Therefore, applications that rely on these constants are affected.+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. The file path obtained by **error reporting**, **exceptions**, **reflections**, will also be the path to the compiled file, not the current opcode file path.
Line 84: Line 95:
     * set 1, default value, different version opcode file exec are prohibited     * set 1, default value, different version opcode file exec are prohibited
     * set 0, different version opcode file will report **E_WARNING** message     * set 0, different version opcode file will report **E_WARNING** message
 +
 +===== Some  scenarios =====
 +  - This RFC will avoid cold start on the WEB service and avoid opcache expiration. For example, when deploying PHP applications through docker, cold starts are avoided when adding docker services.
 +  - Desktop applications developed with PHP, but require some code protection to avoid being easily modified. For example, internal systems, but can avoid non-professional error modifications.
 +  - Zend Guard can be simply replaced.
 +  - The php project is compiled into a binary file instead of packaged into a file.
 +  - To some extent, the security of code deployed on public servers is protected, such as shared hosts
 +
 +===== Vote =====
 +Voting opens 2021-04-05 and 2021-04-20 at 00:00:00 UTC. 2/3 required to accept.
 +
 +<doodle title="Add OPCache direct execution opcode without source file" auth="chopins" voteType="single" closed="true">
 +   * Yes
 +   * No
 +</doodle>
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
Line 90: Line 116:
 ===== Implementation ===== ===== Implementation =====
 [[https://github.com/php/php-src/pull/6146/commits/75fbf645c431f1afbcc4418ddda86f5afec98853|75fbf645c431f1afbcc4418ddda86f5afec98853]] [[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]]
rfc/direct-execution-opcode.1607603616.txt.gz · Last modified: 2020/12/10 12:33 by chopins