views:

49

answers:

2

Hi all, I was trying to understand the working of Zend with the help of this excellent article. Its when I found out that Zend Engine was a Virtual Machine.

Now my question is whats the advantage of creating an intermediate code for scripting languages like php?

I can understand that having Intermediate Code in the case of programming languages like Java and CSharp would introduce portability across different platforms like Linux and Windows.

+1  A: 

It is faster to execute bytecode than interpret sourcecode. This bytecode might be cached (this is done via PHP accelerators), thus giving up to 20x performance boost.

BarsMonster
The article claims that it introduces flexibility to php. Any comments on that?
Karthick
The claim is explained in the text following "A VM provides flexibility to PHP." And it boils down to "A VM is always slower than the physical machine it runs on, so extra speed is gained by performing complex instructions as a single VM operation".
VolkerK
My question is how does it provide flexibility? "A VM is always slower than the physical machine it runs on, so extra speed is gained by performing complex instructions as a single VM operation".. I don understand who this answers my question on flexibility!
Karthick
BarsMonster
So u mean to say that Caching and speed enhancement is the only purpose of VM in the case of PHP?
Karthick
Exactly. Another thing is Encription, which is commercial feature of Zend.
BarsMonster
Can you explain me a little more on the Encryption?
Karthick
http://www.zend.com/products/guard/
BarsMonster
+1  A: 

The term VM in the article is completely wrong. In reality he's describing that PHP compiles the scripts to bytecode, and this bytecode will be interpreted, there's NO vm inside of PHP.

The bytecode operations (opcode) are only an efficient representation of a php script to run the statements one after another and store the results correctly. Have a look at "Abstract Syntax Tree"s to fully understand the bytecode and their advantage for every language.

Tobias P.