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
Next revisionBoth sides next revision
rfc:direct-execution-opcode [2020/12/10 11:56] chopinsrfc:direct-execution-opcode [2020/12/10 14:30] – add scenarios chopins
Line 7: Line 7:
  
 ===== 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 13: Line 15:
  
 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. 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: Change function to:
Line 19: 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 path, the opcode file format change to like below: 
 + 
 +<PHP> 
 +<?phpo{phpversionid}OPCACHE575d367cc725713f6f170910d6e9ee5e-------BINARY CONTENT OF OPCODE---- 
 +</PHP>
  
-php--->load code--->compile to opcode--->save to cache system directory-->same path file-->**copy cache file to the specified path**+**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 exec process:**+=== 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 =====
-This change causes **%%__FILE__%%** path obtained by the constant is not the path to the opcode file, but the path to the compiled PHP file.**%%__DIR__%%** this is also the problem.+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. 
 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 76: Line 95:
     * set 0, different version opcode file will report **E_WARNING** message     * set 0, different version opcode file will report **E_WARNING** message
  
-===== Future Scope ===== +===== Some  scenarios ===== 
-support opcode file in phar.+  - 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 
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
rfc/direct-execution-opcode.txt · Last modified: 2021/04/23 18:07 by imsop