Domanda

The question is mostly related to PHP because IMHO opcode is mostly mentioned in PHP context. According to this description, here's a transformation process of php code into opcode:

php text -> scanning/parsing -> result = tokens -> compiling > result = opcode

Several questions here:

1) Is opcode just a portion of machine code, does machine code consist of opcodes? 2) Thinking in the context of Wamp server, what PHP module is responsible for? Is that module just PHP interpreter who transforms PHP code into tokens or is it also a compiler who compiles tokens into opcode that is executed on the hardware (processor)?

È stato utile?

Soluzione

The question is mostly related to PHP because IMHO opcode is mostly mentioned in PHP context.

In fact Java is more popular for its byte-/opcode

1) Is opcode just a portion of machine code, does machine code consist of opcodes?

Yes, but this opcodes are machine-dependent. The interesting thing in Java or PHP bytecode is that it's machine independent and runs in a platform-specific virtual machine.

2) Thinking in the context of Wamp server, what PHP module is responsible for?

No module, it's part of the core.

Lexer => Tokenizer => Compiler

Is that module just PHP interpreter who transforms PHP code into tokens or is it also a compiler who compiles tokens into opcode that is executed on the hardware (processor)?

Not exactly. The resulting bytecode is machine-independent (named "Zend-opcode") and cannot run directly on the hardware. The last step is to transform this bytecode into machine-dependent opcodes.

Altri suggerimenti

  • Machine code - code which is ready to be executed by machine processor
  • opcode - code to be executed by an interpreter

Opcode is executed by php core, it's internal feature. For speeding up php scripts there is a module PHP Accelerator, which caches compiled bytecode so that next time it would be executed by the processor directly

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top