Mind Map click to view big chart
As a php development engineer, to improve the technology, you must have a deeper understanding of C. PHP engineers are most exposed to the Apache server, so today they will be trained first. For more information, see. Apache supports many features, most of which are implemented through module extension.
Preparation Conditions to install Apache. the version I installed is the httpd-2.2.22, pay attention to the high version in the installation process problems are more, it is recommended to install a lower version. Install the SDK Based on the install file in httpd. Apache installation directory is/opt/modules/httpd source file:/home/zhoubaochuan/download/httpd-2.2.22 module processing process when running under the Apache server, in general, it is integrated in the form of "Mod _ Module name.
1> the MOD module accepts requests passed by Apache. 2. processes these requests. 3. returns the processed results to Apache. Note: For each module, the file name must start with "Mod. For example, mod_test.c. -- If the naming format is incorrect, Apache considers this module illegal. Apache runs in the startup and running stages.
Startup phase
> The startup will be completed by the privileged user root or super administrator.
> The entire process is in a single thread. Including Configuration File Parsing (HTTP. conf), module loading (such as mod_test), and System Resource Initialization (such as log files, shared memory segments, and database links)
> In this stage, many slow or costly operations are concentrated at this stage to reduce the pressure on subsequent request services.
Running stage
> Apache abandons the privileged user level and uses common users, mainly based on security considerations.
> HTTP requests are processed through links, processes, and disconnections.
Check whether the load mechanism is an Apache module: It is implemented by checking the magic field in the module structure. The magic field is represented by standard20_module_stuff. The value of magic in this macro is module_magic_cookie.
Activation Module
Apache will call the related function ap_add_loaded_module to activate the module (activation: Put the module into the corresponding linked list (ap_top_modules linked list, ap_top_modules linked list is used to save all activated modules in Apache .) Every module of Apache exists as a module structure. You can take a closer look at the source code and comments.
Code -- mod_test module as an Example
1. Write a MAKEFILE file first (avoid making a bunch of commands every time and make it all done-it's easy to use! Try it)
2. Write implementation Code
3. Compile the file.
4. Start application in Apache, configure the httpd. conf file, and add the following line of text.
5. Check the effect.
Summary Article It is only a partial implementation process of the Apache module. There are many processing processes in the production environment. Including request processing and authentication. Through the Apache module, we can sometimes directly bypass the implementation mechanism of the Web language and directly store some simple data into the media through the C language, such as files, databases, memory, then, it serves as an API for other services to call. Reference: the Apache modules book -- Application Development with Apache