Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How zend engine compile php codes or How php compiler works?

Hi any body knows how the zend engine compiles php codes. For eg. in java our codes are compiled to byte code after that it converts to machine language. like wise how zend engine compile php codes? Kindly help me.

like image 234
DEVOPS Avatar asked Dec 17 '22 16:12

DEVOPS


1 Answers

It's kind of the same idea with PHP :

  • First step : PHP source code (i.e. some text) is compiled to a set of opcodes
  • Second step : those opcodes are executed.


This compilation, by default, is done each time a PHP script is to be executed -- which takes some CPU.

That is the reason for which you can use some opcode cache (like the APC extension), to store the opcodes in memory -- avoiding the redundant compilation step.


You'll be able to find some interesting informations about those processes in the following presentation by Sebastian Bergmann : PHP Compiler Internals

like image 66
Pascal MARTIN Avatar answered Dec 19 '22 05:12

Pascal MARTIN