If you are working on PHP internals and you need to know which opcodes are generated for a given script, here is the command you can use to dump them.
Assume the file index.php
<?php
echo "hello";
You can dump opcodes running the command
$ php -n -d zend_extension=opcache.so -d opcache.enable=1 -d opcache.enable_cli=1 -d opcache.opt_debug_level=0x10000 index.php
-
-n
: [optional] disable all extensions, you will enable only the ones you are interested in; -
-d zend_extension=opcache.so
: load theZend OPcache
extension; -
-d opcache.enable=1
: enable theZend OPcache
extension; -
-d opcache.enable_cli=1
: enable theZend OPcache
extension for the CLI SAPI (required for the command line); -
-d opcache.opt_debug_level=0x10000
: disable opcodes optimization - docs.
The output of this command is
$_main: ; (lines=2, args=0, vars=0, tmps=0)
; (before optimizer)
; /var/www/html/public/index.php:1-10
L0: ECHO string("hello")
L1: RETURN int(1)
Originally, inspired by the excellent Nikita Popov's post about the PHP 7 virtual machine.
Top comments (0)