Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the principle of PHP program execution?

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces you what is the principle of PHP program implementation, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Static void php_init_handler (server_rec * s, pool * p) {register_cleanup (p, NULL, (void (*) (void *)) apache_php_module_shutdown_wrapper, (void (*) (void *)) php_module_shutdown_for_exec); if (! apache_php_initialized) {apache_php_initialized = 1; # ifdef ZTS tsrm_startup (1,1,0, NULL) # endif sapi_startup (& apache_sapi_module); php_apache_startup (& apache_sapi_module);} # if MODULE_MAGIC_NUMBER > = 19980527 {TSRMLS_FETCH (); if (PG (expose_php)) {ap_add_version_component ("PHP/" PHP_VERSION);}} # endif}

This function mainly calls two functions: sapi_startup (& apache_sapi_module) and php_apache_startup (& apache_sapi_module)

SAPI_API void sapi_startup (sapi_module_struct * sf) {sf- > ini_entries = NULL; sapi_module = * sf;. Sapi_globals_ctor (& sapi_globals); Virtual_cwd_startup (); / * Could use shutdown to free the main cwd but it would just slow it down for CGI * /. Reentrancy_startup ();}

Sapi_startup creates a sapi_globals_struct structure. Sapi_globals_struct stores the basic information of the Apache request, such as server information, Header, encoding and so on. Execute the php_apache_startup after the execution of the sapi_startup.

Static int php_apache_startup (sapi_module_struct * sapi_module) {if (php_module_startup (sapi_module, & apache_module_entry, 1) = = FAILURE) {return FAILURE;} else {return SUCCESS;}}

There is too much content in php_module_startup, so here's a general description of what it does:

1. Initialize the zend_utility_functions structure. This structure sets the function pointer of zend, such as error handler, output function, stream operation function, etc.

two。 Set the environment variable.

3. Load php.ini configuration.

4. Load php built-in extensions.

5. Keep a journal.

6. Register the php internal function set.

7. Call php_ini_register_extensions to load all external extensions

8. Turn on all extensions

9. Some cleaning operations.

Let's focus on 3pm, 4pm, 7pm 8.

Load php.ini configuration

If (php_init_config (TSRMLS_C) = = FAILURE) {return FAILURE;}

The php_init_config function checks all php.ini configurations here, finds all loaded modules, and adds them to the php_extension_lists structure.

Load php built-in extensions

Call zend_register_standard_ini_entries to load all php's built-in extensions, such as array,mysql, and so on.

Call php_ini_register_extensions to load all external extensions

Main/php_ini.c

Void php_ini_register_extensions (TSRMLS_D) {zend_llist_apply (& extension_lists.engine, php_load_zend_extension_cb TSRMLS_CC); zend_llist_apply (& extension_lists.functions, php_load_php_extension_cb TSRMLS_CC); zend_llist_destroy (& extension_lists.engine); zend_llist_destroy (& extension_lists.functions);}

The zend_llist_apply function traverses extension_lists and executes the callback function php_load_php_extension_cb

Static void php_load_zend_extension_cb (void * arg TSRMLS_DC) {zend_load_extension (* (char * *) arg);}

The function is last called

If ((module_entry = zend_register_module_ex (module_entry TSRMLS_CC)) = = NULL) {DL_UNLOAD (handle); return FAILURE;}

Put the extended information into the Hash table module_registry, Zend/zend_API.c

If (zend_hash_add (& module_registry, lcname, name_len+1, (void*) module, sizeof (zend_module_entry), (void**) & module_ptr) = = FAILURE) {zend_error (E_CORE_WARNING, "Module\% s\ 'already loaded", module- > name); efree (lcname); return NULL;}

What is the principle of PHP program implementation is shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report