[PHP] PHP and Apache modules, phpapache

Source: Internet
Author: User

[PHP] PHP and Apache modules, phpapache

1. When PHP needs to run under the Apache server

In general, it can be integrated in the form of the mod_php5 module. In this case, the mod_php5 module is used to receive PHP file requests passed by Apache, process these requests, and then return the processed results to Apache.
There are two loading methods: loading at Apache startup or dynamic loading at runtime.

2. Apache running process
Apache runs in the startup and running stages. In the startup phase, Apache uses the privileged user root (* nix system) to obtain the maximum permission to use system resources)
The whole process is in a single process and single thread environment. This phase includes parsing configuration files (such as http. conf file), module loading (such as mod_php and mod_perl), and System Resource Initialization (such as log files, shared memory segments, database connections, etc. In the running stage, Apache mainly processes users' service requests. At this stage, Apache abandons the privileged user level and uses common permissions. This is mainly based on security considerations to prevent security vulnerabilities caused by code defects.
The Hook mechanism is used to inject the udfs of mod_php5 into the request processing loop and participate in php processing.

3. Apache2 mod_php5 module description
Module struct in Apache, which defines many Members
The mod_php5 module in PHP is defined using this struct and assigned a value. There is a php_dir_cmds member. It is an array containing several php commands, such as php_value and php_admin_value.

 

Structure defined by Apache:

typedef struct module_struct module;struct module_struct {    int version;    int minor_version;    int module_index;    const char *name;    void *dynamic_load_handle;    struct module_struct *next;    unsigned long magic;    void (*rewrite_args) (process_rec *process);    void *(*create_dir_config) (apr_pool_t *p, char *dir);    void *(*merge_dir_config) (apr_pool_t *p, void *base_conf, void *new_conf);    void *(*create_server_config) (apr_pool_t *p, server_rec *s);    void *(*merge_server_config) (apr_pool_t *p, void *base_conf, void *new_conf);    const command_rec *cmds;    void (*register_hooks) (apr_pool_t *p);}

Assign values to struct in PHP:

AP_MODULE_DECLARE_DATA module php5_module = {STANDARD20_MODULE_STUFF,/* macro, including version, minor version, module index, module name, next module pointer, and other information, the module name is represented by _ FILE _ */create_php_config,/* create per-directory config structure */merge_php_config,/* merge per-directory config structures */NULL, /* create per-server config structure */NULL,/* merge per-server config structures */php_dir_cmds,/* All commands defined by the module */php_ap2_register_hook/* Registration hook, this function registers hooks for specified steps during a request processing using a function starting with ap_hoo _ */}; const command_rec php_dir_cmds [] = {AP_INIT_TAKE2 ("php_value", php_apache_value_handler, NULL, OR_OPTIONS, "PHP Value Modifier"), AP_INIT_TAKE2 ("php_flag", expiration, NULL, OR_OPTIONS, "PHP Flag Modifier"), AP_INIT_TAKE2 ("php_admin_value", expiration, NULL, ACCESS_CONF | RSRC_CONF, "PHP Value Modifier (Admin)"), AP_INIT_TAKE2 ("php_admin_flag", signature, NULL, ACCESS_CONF | RSRC_CONF, "PHP Flag Modifier (Admin )"), AP_INIT_TAKE1 ("PHPINIDir", php_apache_phpini_set, NULL, RSRC_CONF, "Directory containing the php. ini file "), {NULL }};

My exercises:


1. C language Array
Int a [] = {1, 2, 4}; // an integer Array
Char * B [] = {"tao", "shi", "han"}; // String Array
Printf ("% d % s \ n", a [2], B [0]);

2. typedef: alias for the Type

Int main () {// defines the struct stu {char * name; int age; int (* sum) (int );}; // give the type an alias typedef struct stu STU; // 1. defines the struct STU student; student. age = 10; student. name = "taoshihan"; printf ("% s \ n", student. name );}

 

3. A few predefined macros:
Printf ("% d \ n" ,__ LINE _); // returns the current row number
Printf ("% s \ n" ,__ FILE _); // return the name of the Current Source FILE

4. const: do not modify the variable value, constant

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.