Home  >  Article  >  Operation and Maintenance  >  Introduction to the working mode of apache

Introduction to the working mode of apache

王林
王林forward
2020-06-28 17:40:383672browse

Introduction to the working mode of apache

Apache’s working mode

(Recommended tutorial: apache from entry to proficiency)

prefork work Principle

A separate control process (parent process) is responsible for generating child processes, which are used to listen to requests and respond.

Apache always tries to keep some spare or idle child processes for upcoming requests. In this way, the client does not need to wait for the child process to be generated before getting the service. In Unix systems, the parent process usually runs as root to bind port 80, while the child process generated by Apache usually runs as a low-privileged user.

User and Group directives are used to configure low-privilege users for child processes. The user running the child process must have read permissions on the content he is serving, but must have as few permissions as possible on other resources outside the service content.

How worker works

The number of threads each process can have is fixed. The server will increase or decrease the number of processes based on load.

A separate control process (parent process) is responsible for the establishment of child processes. Each child process can establish a ThreadsPerChild number of service threads and a listening thread, which listens for access requests and passes them to the service thread for processing and response. Apache always tries to maintain a spare or idle pool of service threads.

In this way, the client does not need to wait for a new thread or new process to be established before it can be processed. In Unix, in order to be able to bind port 80, the parent process is usually started as root. Subsequently, Apache creates child processes and threads as users with lower privileges. The User and Group directives are used to configure the permissions of the Apache child process. Although the child process must have read access to the content it provides, it should be given as few privileges as possible.

In addition, unless suexec is used, the permissions configured by these instructions will be inherited by the CGI script.

Event MPM

This is the latest working mode of Apache. It is very similar to the worker mode. The difference is that it solves the problem of keeping-alive long connections. The problem of wasted thread resources. In the event working mode, there will be some special threads used to manage these keep-alive type threads. When a real request comes, the request will be passed to the server thread. After the execution is completed, and allowed it to be released.

This enhances request processing in high concurrency scenarios. The apache2.4 version in unix systems uses this mode.

The above is the detailed content of Introduction to the working mode of apache. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:juejin.im. If there is any infringement, please contact admin@php.cn delete