rfc:direct-execution-opcode
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:direct-execution-opcode [2020/12/10 11:56] – chopins | rfc:direct-execution-opcode [2020/12/18 14:39] – chopins | ||
---|---|---|---|
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: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
===== 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 |
+ | |||
+ | 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: | ||
</ | </ | ||
- | ==== Implementation Method==== | + | ==== Implement a schematic flowchart |
- | **compile to file:** | + | === The PHP source code file is compiled into an opcode file flowchart: === |
- | 1. current | + | 1. current |
+ | < | ||
+ | [php-load-source] ---> [compile to opcode] ---> | ||
+ | </ | ||
- | php**--->**load code**--->**compile to opcode | + | 2. path change to process: |
+ | < | ||
+ | [php-load-source] | ||
+ | </ | ||
- | 2. path added optional: | + | 3. When specified |
- | php--->load code--->compile to opcode--->save to cache system directory-->same path file-->**copy cache file to the specified | + | < |
+ | <? | ||
+ | </PHP> | ||
+ | |||
+ | **The above code explains: | ||
+ | - **<? | ||
+ | - **{phpversionid}**: | ||
+ | | ||
+ | - **-------BINARY CONTENT OF OPCODE----**: | ||
- | **opcache | + | === OPCache extentsion |
- | 1. current opcache exec: | + | 1. current opcache exec process: |
<PHP> | <PHP> | ||
- | [php]--> | + | [php] ---> [find cache in cache system directory] |
- | | + | |
</ | </ | ||
- | 2. path added optional: | + | 2. path added process: |
<PHP> | <PHP> | ||
- | [php/ | + | [php/ |
- | \---->[not phpo] ---> [find cache in cache system directory]--> | + | |
- | | + | \---> [not found] |
</ | </ | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
- | This change causes | + | 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' |
+ | So magic constant | ||
The file path obtained by **error reporting**, | The file path obtained by **error reporting**, | ||
Line 76: | Line 96: | ||
* 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 | + | - 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 ===== | ||
Line 84: | Line 109: | ||
===== Implementation ===== | ===== Implementation ===== | ||
[[https:// | [[https:// | ||
+ | |||
+ | ===== References ===== | ||
+ | - [[https:// | ||
+ | - [[https:// |
rfc/direct-execution-opcode.txt · Last modified: 2021/04/23 18:07 by imsop