First, what is an Opcode? It's a compiled form of a PHP script, similar to Java bytecode. Or, more precisely, from php.net
"When parsing PHP files, Zend Engine 2 generates a series of operation codes, commonly known as "opcodes", representing the function of the code."
For a script like this, the opcodes look like that:
Now that you have installed it, you need to load it. In your php.ini, add the following, best if you put it close to extension=modulename.extension.
You find your php.ini by running
To generate the opcodes, all you need to do now is run the script with the following parameters (-d for ini entries)
"When parsing PHP files, Zend Engine 2 generates a series of operation codes, commonly known as "opcodes", representing the function of the code."
<?php $a = "Hello "; $b = "World\n"; echo $a . $b;
For a script like this, the opcodes look like that:
number of ops: 5 compiled vars: !0 = $a, !1 = $b line # * op fetch ext return operands --------------------------------------------------------------------------------- 2 0 > ASSIGN !0, 'Hello+' 3 1 ASSIGN !1, 'World%0A' 4 2 CONCAT ~2 !0, !1 3 ECHO ~2 5 4 > RETURN 1 branch: # 0; line: 2- 5; sop: 0; eop: 4 path #1: 0,
Translate Sourcecode to op_array
Whoa. Now, how do you get the opcodes, i.e., op_array? You need a PHP extensions, like VLD (Vulcan Logic Disasembler). If you have pecl installed, you can download, build, and install it in one step by running> sudo pecl install vld
If you get an error message about a stable version, try running
> sudo pecl install vld-0.12.0
Now that you have installed it, you need to load it. In your php.ini, add the following, best if you put it close to extension=modulename.extension.
; for op code extension=vld.so
You find your php.ini by running
> php --ini Configuration File (php.ini) Path: /usr/local/zend/etc
To generate the opcodes, all you need to do now is run the script with the following parameters (-d for ini entries)
> php -d vld.active=1 -d vld.execute=0 -f helloWorld.php
Comments
Post a Comment