Introduction to the

The Zend Engine is the open source scripting engine that interprets the PHP programming language.

Zend Engine is an open source scripting engine that interprets the PHP language.

Zend has two parts, a compiler and an executor. The compiler is responsible for compiling PHP code into abstract syntax trees and then further compiling it into executable opcodes. This process is equivalent to GCC. The compiler is the basis of a language implementation. The executor is responsible for executing Opcodes output by the compiler, which is to execute code logic written in the PHP script. OPCODE is a Zend Virtual Machine readable instruction generated by compiling PHP code. There are 173 OPCODES in PHP7, which are defined in Zend_VM_OPCODE.h. All syntax implementations in PHP are composed of these OPCODES.

One of the main features of the Zend Engine is to change the way PHP interprets and executes to Compile and then Execute.

Detailed principle

See link 3 (I didn’t read it all, I don’t understand it, I’m still too young ~~).

The advantages and disadvantages

  • Implementation efficiency has been greatly improved
  • Reduced decoupling and extensible enhancement
  • Zend Engine divides code into compilation and execution. In general, we rarely change our code once it’s done. However, PHP has to be recompiled during execution, which is time-consuming and a waste of resources. (That’s where Opcache comes in.)

Opcode

Opcode is an intermediate language for compiled PHP scripts, like Java’s Bytecode, or. .net MSL. PHP executes the code through the following four steps (specifically, PHP’s Zend language engine):

(1).Scanning(Lexing) is used to transform PHP code into Tokens. (2).Parsing Tokens into simple and meaningful expressions. Execute Opcodes one at a time to enable PHP script functionality.

There are some existing caches, such as APC and Opcache(APC only works with PHP 5.4, Zend Opcache is integrated with PHP 5.5, instead of APC). This allows PHP to cache Opcodes so that every time a request comes in, there is no need to repeat the previous 3 steps, thus greatly improving the execution speed of PHP. The diagram below:

episode

Once the code was sent online (the database was modified), but the data in the database did not come in, which was very weird. I suspected that the code was not sent successfully. Later, the leader told the operation and maintenance in the group that the Opcache (the theory is that the cache Opcodes are not updated)… Small pit pit

reference

  1. http://www.careerride.com/PHP-zend-engine.aspx
  2. https://www.kancloud.cn/nickbai/php7/363257
  3. https://github.com/pangudashu/php7-internal/blob/master/3/zend_executor.md
  4. http://www.nowamagic.net/librarys/veda/detail/1291
  5. https://www.cnblogs.com/JohnABC/p/4531029.html
  6. http://www.laruence.com/2008/06/18/221.html