Home > Backend Development > PHP Problem > Several types of integration between php and apache

Several types of integration between php and apache

王林
Release: 2023-02-26 07:22:02
Original
2880 people have browsed it

Several types of integration between php and apache

1. CGI

CGI (common gateway interface) is usually translated as common gateway interface, which is the connection between the HTTP server and other programs on the machine. An interface for communication that allows the web server to start additional programs to handle dynamic content when necessary. CGI is a protocol that defines how the Webserver communicates with CGI programs. The Webserver accepts the client's HTTP request, and then creates a process to execute the CGI program. The client's request is passed to the CGI program, and the result is returned to the Webserver after the CGI is executed.

The emergence of CGI has changed the WEB from static to dynamic. As the Web becomes more and more popular, many websites need dynamic pages to interact with viewers. With the development of network technology, the shortcomings of CGI methods have become more and more prominent. Each client request requires the process to be established and destroyed. Because HTTP needs to generate a dynamic page, the system must start a new process to run the CGI program. Continuous forking is a very time- and resource-consuming task.

2. FastCGI

As we all know, repeated loading of the CGI interpreter is the main reason for low CGI performance. If the CGI interpreter remains in memory and accepts FastCGI process management Server scheduling can provide good performance, scalability, Fail-Over features, etc.

FastCGI is a resident CGI that can be executed all the time. As long as it is activated, it will not take time to fork every time, and it also supports distributed computing (so that the PHP program interpretation and execution can be left to a separate php server), that is, it can be executed on a host other than the website server and accept requests from other website servers.

1. Load the FastCGI process manager (IIS ISAPI or Apache Module) when the Web Server starts;

2. The FastCGI process manager initializes itself and starts multiple CGI interpreter processes (in Multiple php-cgi.exe are visible in the task manager and are waiting for connections from the Web Server.

3. When the 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.exe.

4. 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 WebServer). In normal CGI mode, php-cgi.exe exits here.

3. Module

To compile php into an apache module, you must consider the working mode of apache's MPM.

First we need to understand what MPM is:

MPM: Multi Path Modules (multi-path processing modules) are used to define the work of apache when responding to multiple user requests model. There are three MPM modes:

prefork (one request is responded to by one process);

worker (one request is responded to with one thread, multiple processes are started and each process generates multiple threads);

event (one process handles multiple requests);

PHP installed as a module does not have an independent process and is started as an apache module together with apache.

Among the above three MPM modes, the worker mode will occupy less memory than the prefork mode and perform better under high concurrency. Moreover, using the multi-process and multi-thread mixed mode, even if one thread hangs up, it will only affect other threads in the same process as the thread and will not affect other processes. However, if there are a particularly large number of threads using the keep-alive long connection method, the threads will be occupied until timed out, resulting in no available threads in high concurrency scenarios. The event mode uses a dedicated thread to handle these keep-alive threads, which better solves this problem.

Recommended tutorial: PHP video tutorial

The above is the detailed content of Several types of integration between php and apache. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template