PHP architecture and its implementation Overview:
PHP uses a typical modular and layered idea. Convenient expansion and maintenance. From top to bottom:
I. SAPI
Server Application Programming Interface (SAPI) server application programming port.
It seems like a very profound concept. To put it bluntly, it is such a thing, the serverProgram(For example, Apache, ngnix) and peripheral programs define a convention to provide several functions, their function name is XXX. The parameter is XXX, and then we can call them normally (such as PHP, such as ASP or some server plug-ins ). For example, if you are communicating with Apache in Linux, you are calling apache_2.x.so.
Ii. php extension Components
It provides PHP with some extended components, such as our commonly used MySQL driver, encrypted encryption and decryption components. These components provide some extensions for PHP. In PHP, we can call them through function calls.
Iii. php Layer
It is responsible for interacting with the SAPI layer to control the entire PHP running process. That is to say, call extension and Zend core. It also includes some core PHP components such as file processing.
4. Zend Engine
PHP core implementation, PHP compilation process (lexical analysis, syntax analysis, semantic analysis, etc.) to generate opcode and execute opcode. It is actually a compiler and a virtual machine.
PHP Execution is divided into two situations: Command Line execution mode and PHP Web page execution mode.
When executing the command line:
First, some environments will be initialized, including loading the configuration file and loading the extension components. Second, call the Zend Core Engine to generate opcode. Then run this opcode. If an extension function is called during execution, the corresponding extension component entry function is called.
After the final execution, clean up the site, including releasing the memory.
Webpage execution: (take Apache as an example)
There are two modes configured through Apache. One is the module mode. In this mode, when Apache is started, a PHP module is loaded to create a PHP processing process and wait for the request. But the final execution is. the PHP process is called to process the PHP file. The process is the same as that in the command line. After the process is completed, the output is returned to Apache. Apache is responsible for returning an HTTP Response to the client.
One mode is CGI Mode. The CGI Mode does not pre-load the PHP module, but generates a PHP process each request. Send a message to the PHP process for processing. After processing, the message is returned to apapche.
This is the study Note of the younger brother: there may be many mistakes in understanding, and I beg you to help me correct your opinions for progress.