Home  >  Article  >  Backend Development  >  PHP life cycle

PHP life cycle

藏色散人
藏色散人forward
2019-11-08 15:22:042582browse

PHP Architecture Diagram

PHP life cycle

SAPI

SAPI(Server Application Programming Interfac ) is an application programming interface (API) provided by the web server to help other developers in extending the web server capabilities. Interface (api). It abstracts external conditions and provides a set of fixed and unified interfaces for internal PHP, so that PHP's own implementation can not be affected by the external environment and maintain a certain degree of independence.

Commonly used SAPIs in PHP include cli (command line mode, single process), php-fpm, CGI, Apache...

It is a bit like the strategy mode, using the same interface, but implementing It will be slightly different.

PHP life cycleStartup and termination of PHP

● Starting phase before request:

MINIT:

Module initialization phase. Initialize some extensions, constants, classes, resources, etc., all things used by PHP scripts. (Resident memory, can be used by all requests.)

PRINT:

Module activation phase. PHP will call the RINIT function of all modules. At this stage, each module can also perform some related operations, such as initializing the variables used in this request.

● The end stage after the request:

RSHUTDOWN:

The request for this page has been executed, or it has been die (exit) by the user. At this time, PHP will start the recycling program , to recycle the resources used by this request. This time, the RSHUTDOWN (commonly known as Request Shutdown) method of all loaded extensions will be executed. At this time, the extension can use the variable table in the kernel to do some things. Because once PHP executes all extended RSHUTDOWN methods, it will release all resources used in this request, such as all variables in the variable table, all memory requested in this request, etc.

MSHUTDOWN:

PHP executes all extended MSHUTDOWN and releases resources.

Life cycle of PHP

1. Single-process SAPI life cycle (CLI/CGI)

2 .Multi-process SAPI life cycle (Apache2)PHP life cycle

3.Multi-threaded SAPI life cyclePHP life cycle

4.Embed PHP life cycle

Embed SAPI is a special sapi that allows you to call functions provided by PHP/ZE in C/C language.

Overview

Let’s take a look at the life cycle of PHP and the entire execution process of PHP. And how to communicate with PHP module through SAPI.

The above is the detailed content of PHP life cycle. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete
Previous article:PHP template engineNext article:PHP template engine