What is the life cycle of PHP7
This article will introduce you to the life cycle of PHP7. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
PHP Architecture
SAPI Introduction
Definition: Server Application Programming InterfaceServer Application Programming port. It is the interface for PHP to interact with other applications. PHP scripts can be executed in many ways, through the web server, directly on the command line, or embedded in other programs. SAPI provides an interface for external communication. Common SAPIs include: cgi, fast-cgi, cli, Apache module dll, etc.
CGI
CGI is the common gateway interface (common gateway interface). It is a program. In layman's terms, CGI is like a bridge. , connects the web page and the execution program in the WEB server, it passes the instructions received by the HTML to the server's execution program, and then returns the results of the server's execution program to the HTML page. CGI is extremely cross-platform and can be implemented on almost any operating system.
When the CGI method encounters a connection request (user request), it must first create a cgi sub-process, activate a CGI process, then process the request, and end the sub-process after processing. This is the fork-and-execute pattern. Therefore, a server using CGI will have as many CGI sub-processes as there are connection requests. Repeated loading of sub-processes is the main reason for low CGI performance. When the number of user requests is very large, a large amount of system resources such as memory, CPU time, etc. will be occupied, resulting in low performance.
FPM (FastCGI)
fast-cgi is an upgraded version of cgi, FastCGI is like a long-live type CGI can be executed all the time. As long as it is activated, it will not take time to fork every time. PHP uses PHP-FPM (FastCGI Process Manager), the full name of PHP FastCGI Process Manager, for management.
The FastCGI process manager (IIS ISAPI or Apache Module) is loaded when the Web Server starts. The FastCGI process manager initializes itself, starts multiple CGI interpreter processes (visible multiple php-cgi) and waits for connections from the Web Server.
When a client request reaches the Web Server, the FastCGI process manager selects and connects to a CGI interpreter. The web server sends CGI environment variables and standard input to the FastCGI subprocess php-cgi.
After the FastCGI sub-process completes processing, it returns standard output and error information to the Web Server from the same connection. When the FastCGI child process closes the connection, the request is processed. The FastCGI child process then waits for and handles the next connection from the FastCGI process manager (running in the Web Server). In CGI mode, php-cgi exits at this point.
In the above case, you can imagine how slow CGI is usually. Every web request to PHP must reparse php.ini, reload all extensions, and reinitialize all data structures. With FastCGI, all of this happens only once, when the process starts. An added benefit is that persistent database connections work.
APACHE2HANDLER
PHP as an Apache module, the Apache server pre-generates multiple process copies to reside in the memory after the system starts. When a request occurs, these idle sub-processes are immediately used for processing, so that there is no delay caused by generating sub-processes. These server copies do not exit immediately after processing an HTTP request, but stay in the computer waiting for the next request. The response to client browser requests is faster and the performance is higher.
CLI
cli is the command line running mode of php. You often use it, but you may not notice it (for example: we Under Linux, "php -m" is often used to find out which extensions PHP has installed, which is the PHP command line running mode.
SAPI process
Structure:
struct _sapi_module_struct { char *name; char *pretty_name; int (*startup)(struct _sapi_module_struct *sapi_module); int (*shutdown)(struct _sapi_module_struct *sapi_module); int (*activate)(void); int (*deactivate)(void); size_t (*ub_write)(const char *str, size_t str_length); void (*flush)(void *server_context); … }
Calling API :
Called when the module starts:
int (*startup)(struct _sapi_module_struct *sapi_module);
Called when the module ends:
int (*shutdown)(struct _sapi_module_struct *sapi_module);
Called when processing the request:
int (*activate)(void);
Called after processing the request:
int (*activate)(void);
SAPI
structure corresponding to CGI mode:
SAPI
structure corresponding to FPM mode:
Life cycle of FPM mode:
The above is the detailed content of What is the life cycle of PHP7. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



vue3 changed 4 life cycle functions. The Vue3 combined API cancels the beforeCreated and created hook functions and uses the step hook instead, and this cannot be used in it. The hook functions for component destruction in Vue3 have been changed from destroyed and beforeDestroy to beforeUnmount and unmounted.

In C++, function pointers require proper destruction and life cycle management. This can be achieved by manually destructing the function pointer and releasing the memory. Use smart pointers, such as std::unique_ptr or std::shared_ptr, to automatically manage the life cycle of function pointers. Bind the function pointer to the object, and the object life cycle manages the destruction of the function pointer. In GUI programming, using smart pointers or binding to objects ensures that callback functions are destructed at the appropriate time, avoiding memory leaks and inconsistencies.

The Servlet life cycle refers to the entire process from creation to destruction of a servlet, which can be divided into three stages: 1. Initialization stage, calling the init() method to initialize the Servlet; 2. Running stage (processing requests), the container will Request to create a ServletRequest object representing an HTTP request and a ServletResponse object representing an HTTP response, and then pass them as parameters to the service() method of the Servlet; 3. Destruction phase.

In php5, we can use the fsockopen() function to detect the TCP port. This function can be used to open a network connection and perform some network communication. But in php7, the fsockopen() function may encounter some problems, such as being unable to open the port, unable to connect to the server, etc. In order to solve this problem, we can use the socket_create() function and socket_connect() function to detect the TCP port.

To resolve the plugin not showing installed issue in PHP 7.0: Check the plugin configuration and enable the plugin. Restart PHP to apply configuration changes. Check the plugin file permissions to make sure they are correct. Install missing dependencies to ensure the plugin functions properly. If all other steps fail, rebuild PHP. Other possible causes include incompatible plugin versions, loading the wrong version, or PHP configuration issues.

Vue3 is currently one of the most popular frameworks in the front-end world, and the life cycle function of Vue3 is a very important part of Vue3. Vue3's life cycle function allows us to trigger specific events at specific times, enhancing the high degree of controllability of components. This article will explore and explain in detail the basic concepts of Vue3's life cycle functions, the roles and usage of each life cycle function, and implementation cases, to help readers quickly master Vue3's life cycle functions. 1. Vue3’s life cycle function

How to install the mongo extension in php7.0: 1. Create the mongodb user group and user; 2. Download the mongodb source code package and place the source code package in the "/usr/local/src/" directory; 3. Enter "src/" directory; 4. Unzip the source code package; 5. Create the mongodb file directory; 6. Copy the files to the "mongodb/" directory; 7. Create the mongodb configuration file and modify the configuration.

Controlling the life cycle of a Go coroutine can be done in the following ways: Create a coroutine: Use the go keyword to start a new task. Terminate coroutines: wait for all coroutines to complete, use sync.WaitGroup. Use channel closing signals. Use context context.Context.
