Home > Article > Backend Development > PHP kernel-detailed explanation of Zend engine
In the previous chapter, we introduced the life cycle of PHP, PHP’s SAPI, and SAPI are at the upper level of the entire PHP architecture, and the execution of the real script is mainly completed by the Zend engine. In this section we introduce the execution of PHP scripts.
Currently programming languages can be divided into two major categories:
The first category is like C/C++, .NET, Java and the like Compiled languages have one thing in common: the source code must be compiled before running, and then the compiled object file must be run.
The second category is: PHP, Javascript, Ruby, Python and other interpreted languages, they can "run" without compilation ", although it can be understood as directly running
, they are not really directly understood by the machine. The machine can only understand machine language, so these languages How is it executed? Generally, these languages require an interpreter, and the interpreter executes the source code. In fact, these languages will still go through the compilation process, but they are usually compiled in real time when running. For the sake of efficiency, not all languages will be recompiled every time they are executed. For example, PHP's various opcode cache extensions (such as APC, xcache, eAccelerator, etc.), such as Python, will save the compiled intermediate files into pyc/pyo files. , to avoid the performance loss caused by recompiling every time it is run.
<?php $str = "Hello, Tipi!\n"; echo $str; ?>
The execution of PHP scripts also requires an interpreter, such as under the command line php program, or apache's mod_php module, etc. The previous section mentioned PHP's SAPI interface. Let's take the PHP command line program as an example to explain how PHP scripts are executed. For example, the following PHP script:
Assume that the above code is saved in a file named hello.php, and use the PHP command line program to execute this script:
$ php ./hello.php
The output of this code is obviously Hello, Tipi!, so what did PHP/Zend do when executing the script? How do these statements make PHP output this paragraph? The following will introduce it step by step.
That is: lexical analysis => syntactic analysis => ; opcode (intermediate code) compilation =>Zend Engineer execution
##
The above is the detailed content of PHP kernel-detailed explanation of Zend engine. For more information, please follow other related articles on the PHP Chinese website!