PHP Bottom Depth Exploration (4)---Analysis of the operation stage of Apache

Source: Internet
Author: User

Just today yesterday morning when the teacher said a little bit, as to expand and improve it.

2. Operation Stage

2.1 Running Phase Overview

In the runtime, Apache's main job is to handle the user's service requests.

At this stage, Apache abandons the privileged user level and uses normal permissions, primarily based on security considerations, to protect against vulnerabilities caused by code flaws. Like Microsoft's IIS has been subjected to "Code Red" and "Nimda (NIMDA)" and other malicious code overflow attacks.

2.2 Run Phase process
Apache divides the request processing cycle into 11 phases, followed by: Post-read-request,uri Translation,header parsing,access control,authentication, Authorization,mime Type Checking,fixup,response,logging,cleanup.

Apache Hook mechanism

Apache's hook mechanism means that Apache allows modules (including internal modules and external modules, such as mod_php5.so,mod_perl.so, etc.) to inject custom functions into the request processing loop. In other words, the module can hook up its own processing function at any one of the Apache processing stages to participate in the Apache request processing process.


Mod_php5.so/php5apache2.dll is the inclusion of custom functions that are injected into Apache through the hook mechanism and are responsible for processing PHP requests at various stages of the Apache processing process.


The hook mechanism is also frequently encountered in Windows system development, with both system-level hooks and application-level hooks in Windows development. Common translation software (such as PowerWord, etc.) screen-word function, most of them by installing the system-level hook function completed, the custom function to replace the screen output in the Gdi32.dll drawing function.

Apache Request processing Loop detailed
What do the 11 phases of the Apache request processing loop do?

1. Post-read-request Stage

In the normal request processing process, this is the first stage in which a module can insert a hook. This phase can be exploited for modules that want to enter the processing request very early.

2. URI translation phase
The main task of Apache at this stage is to map the requested URL to the local file system. The module can insert a hook at this stage to perform its own mapping logic. Mod_alias is using this phase to work.

3, Header parsing stage
The main task of Apache at this stage: check the requested head. This hook is rarely used because the module can perform the task of checking the request headers at any point in the request processing process. Mod_setenvif is using this phase to work.

4, Access control phase
The main task of Apache at this stage is to check whether the requested resource is allowed to be accessed according to the configuration file. The standard logic of Apache implements the Allow and reject directives. Mod_authz_host is using this phase to work.

5. Authentication Stage
The main work of Apache at this stage: according to the policy set by the configuration file to authenticate the user, and set the user name area. The module can insert hooks at this stage to implement an authentication method.

6. Authorization Stage
The main task of Apache at this stage is to check whether the authenticated user is allowed to perform the requested action based on the configuration file. The module can insert hooks at this stage to implement a method of user rights management.

7, MIME Type checking stage
The main task of Apache at this stage is to determine what content processing functions will be used, based on the relevant rules for the MIME type of the requested resource. Standard modules Mod_negotiation and mod_mime implement this hook.

8. Fixup stage
This is a generic phase that allows the module to run any necessary processing processes before the Content builder. Like Post_read_request, this is a hook that captures any information and is the most commonly used hook.

9. Response Stage
The main task of Apache at this stage is to generate the content that returns the client and to send a proper reply to the client. This phase is the core part of the entire processing process.

10. Logging Stage
The main task of Apache at this stage is to log transactions after the reply has been sent to the client. The module may modify or replace the standard log records of Apache.

11. Cleanup Stage
The main task of Apache at this stage is to clean up the legacy of this request transaction, such as file, directory processing, or socket shutdown, and so on, which is the final stage of Apache request processing.

The module of the injection of Apache process can refer to the source code server/core.c file:

Mod_php5.so/php5apache2.dll injected into the Apache function, the most important is the response phase of the processing function.


Three, PHP processor injected into the process of Apache analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.