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 co开发者_如何学Pythonde after that it converts to machine language. like wise how zend engine compile php codes? Kindly help me.
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
Zend Engine is used internally by PHP as a complier and runtime engine. PHP Scripts are loaded into memory and compiled into Zend opcodes. These opcodes are executed and the HTML generated is sent to the client.
Zend Engine is a interpreter for PHP, you can see at official repository github https://github.com/php/php-src
As simply Zend Engine translate source code PHP to OPCODE (opcode for Zend VM you can see at here https://php-legacy-docs.zend.com/manual/php5/en/internals2.opcodes)
After OPCode finish created ZEND VM execute all OPcode with CPU.
Maybe this presentation can make you more understand about zend (php interpreter) https://thephp.cc/presentations/2019-international-php-conference-php-compiler-internals.pdf
精彩评论