rfc:direct-execution-opcode

This is an old revision of the document!


PHP RFC: Direct execution opcode file without php source code file

Introduction

Allow php direct execution opcode file without php source file.

Proposal

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

Implementation Method

compile to file:

1. current opcache store to file:

php--->load code--->compile to opcode --->store to cache system directory-->same path file

2. path added optional:

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:

<?phpo{phpversionid}OPCACHE575d367cc725713f6f170910d6e9ee5e-------BINARY CONTENT OF OPCODE----

opcache exec process:

1. current opcache exec:

[php]-->[find cache in cache system directory]-->[found] -->[exec opcode]
                                                   \--->[not found]--> [exec php source]

2. path added optional:

[php/phpo]--->[is phpo, <?phpo exist]--->[load the <?phpo file] ---->[exec opcode]
          \---->[not phpo] ---> [find cache in cache system directory]-->[found] -->[exec opcode]
                                                   \------------>[not found] --> [exec php source]-->[auto cache opcode]

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.

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 <?phpo, direct exec opcode file without php source file
  • opcache.prohibit_different_version_opcode
    • set 1, default value, different version opcode file exec are prohibited
    • set 0, different version opcode file will report E_WARNING message

Patches and Tests

Implementation

rfc/direct-execution-opcode.1607603616.txt.gz · Last modified: 2020/12/10 12:33 by chopins