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!

The article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

The article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

The article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.

The article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

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

Dreamweaver CS6
Visual web development tools