rfc:direct-execution-opcode

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.

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

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

The change no incompatible.

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

Future Scope

support opcode file in phar.

Patches and Tests

Implementation

rfc/direct-execution-opcode.txt · Last modified: 2020/11/13 10:18 by chopins