php_module_startup
2015-10-26 22:05:55 0 举报
”php_module_startup”是PHP中的一个钩子函数,它在PHP模块启动时被调用。这个钩子函数允许开发者在模块初始化阶段执行一些操作,例如注册全局变量、设置默认配置选项等。通过实现这个函数,开发者可以自定义模块的行为,以满足特定需求。需要注意的是,这个钩子函数仅在所有其他模块都已启动后才会被调用。总之,”php_module_startup”是一个强大的工具,它为PHP模块的开发者提供了灵活性和可扩展性。
作者其他创作
大纲/内容
sapi_initialize_empty_request(TSRMLS_C);
char *tmp = getenv(\"USE_ZEND_ALLOC\");
php_startup_ticks(TSRMLS_C);
zend_collect_module_handlers(TSRMLS_C);
/* Register Zend ini entries */zend_register_standard_ini_entries(TSRMLS_C);
if (sapi_module.php_ini_path_override) {
void php_ini_register_extensions(TSRMLS_D)
void zend_interned_strings_init(TSRMLS_D)
/*Find and open actual ini file
init lots of SG shit
sapi_deactivate(TSRMLS_C);
zend_uv = *utility_values;zend_uv.import_use_extension_length = strlen(zend_uv.import_use_extension);
//dlopen the .so fileDL_HANDLE handle;zend_extension *new_extension;zend_extension_version_info *extension_version_info;handle = DL_LOAD(path);
gc_globals_ctor_ex(&gc_globals);
/* Add environment location */env_location = getenv(\"PHPRC\
zend_startup_builtin_functions(TSRMLS_C);
if(post_reader_func) {post_reader_func(TSRMLS_C);
zend_init_rsrc_list_dtors();
const zend_ini_entry *p = ini_entry;HashTable *directives = registered_zend_ini_directives;
SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(TSRMLS_D) TSRMLS_DC)
/* Cookies */SG(request_info).cookie_data = sapi_module.read_cookies(TSRMLS_C);
zend_post_startup(TSRMLS_C);
module-module_number = zend_next_free_module();module-type = MODULE_PERSISTENT;
/* Register PHP core ini entries */REGISTER_INI_ENTRIES();
/* allow extension to proclaim compatibility with any Zend version */
static void php_load_php_extension_cb(void *arg TSRMLS_DC)
void php_startup_auto_globals(TSRMLS_D)
return zend_hash_num_elements(&module_registry) + 1;
ZEND_API zend_module_entry* zend_register_module_ex(zend_module_entry *module TSRMLS_DC)
static void sapi_read_post_data(TSRMLS_D)
/* default compile-time values */CG(asp_tags) = asp_tags_default;CG(short_tags) = short_tags_default;CG(compiler_options) = compiler_options_default;
/* disable certain classes and functions as requested by php.ini */php_disable_functions(TSRMLS_C);php_disable_classes(TSRMLS_C);
alloc_globals_ctor(&alloc_globals);
//use the get_module func defined by the module itself//to get the module entry structmodule_entry = get_module();
virtual_cwd_deactivate(TSRMLS_C);
int zend_startup_extensions()
zend_llist_destroy(&extension_lists.engine);zend_llist_destroy(&extension_lists.functions);
static void alloc_globals_ctor(zend_alloc_globals *alloc_globals TSRMLS_DC)
sapi_module = *sf;
php_startup_auto_globals(TSRMLS_C);
int php_init_config(TSRMLS_D)
SAPI_API void sapi_initialize_empty_request(TSRMLS_D)
zend_utility_functions zuf;zuf.error_function = php_error_cb;zuf.printf_function = php_printf;zuf.write_function = php_output_wrapper;zuf.fopen_function = php_fopen_wrapper_for_zend;
/* Otherwise search for php-%sapi-module-name%.ini file in search path */if (!fh.handle.fp) {const char *fmt = \"php-%s.ini\
void zend_set_utility_values(zend_utility_values *utility_values)
/* return the next free module number */ZEND_API int zend_next_free_module(void)
php_ini_file_name = sapi_module.php_ini_path_override;php_ini_search_path = sapi_module.php_ini_path_override;free_ini_search_path = 0;
ZEND_API void zend_collect_module_handlers(TSRMLS_D)
int zend_init_rsrc_list_dtors(void)
void zend_init_opcodes_handlers(void)
ZEND_API int zend_register_constant(zend_constant *c TSRMLS_DC)
void zend_register_standard_ini_entries(TSRMLS_D)
REGISTER_MAIN_LONG_CONSTANT(\"E_ERROR\
SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data)
if (module-module_started) {return SUCCESS;module-module_started = 1;
static void gc_globals_ctor_ex(zend_gc_globals *gc_globals TSRMLS_DC)
if (module_initialized) {return SUCCESS;
int zend_startup_extensions_mechanism()
static char *sapi_cgi_read_cookies(TSRMLS_D)
ZEND_API void start_memory_manager(TSRMLS_D)
while (count--) {if (zend_register_internal_module(ptr++ TSRMLS_CC) == NULL) {
zend_init_opcodes_handlers();
/* Called from php_request_startup() for every request.*/ SAPI_API void sapi_activate(TSRMLS_D)
zend_startup_strtod();
php_binary_init(TSRMLS_C);REGISTER_MAIN_STRINGL_CONSTANT(\"PHP_BINARY\
EG(user_error_handler) = NULL;EG(user_exception_handler) = NULL;、zend_interned_strings_init(TSRMLS_C);
php_scanner_globals_ctor(&language_scanner_globals TSRMLS_CC);
module_shutdown = 0; module_startup = 1;
SG(read_post_bytes) += read_bytes;
static void php_scanner_globals_ctor(zend_php_scanner_globals *scanner_globals_p TSRMLS_DC)
static void ini_scanner_globals_ctor(zend_ini_scanner_globals *scanner_globals_p TSRMLS_DC)
PHPAPI void php_output_register_constants(TSRMLS_D)
zend_module_entry **end = ptr + count;while (ptr end) {if (*ptr) {if (zend_register_internal_module(*ptr TSRMLS_CC)==NULL) return FAILURE;ptr++;
zend_output_globals output_globals;php_output_init_globals(output_globals)
/* set up version */zend_version_info = strdup(ZEND_CORE_VERSION_INFO);zend_version_info_length = sizeof(ZEND_CORE_VERSION_INFO) - 1;
static void zend_set_default_compile_time_values(TSRMLS_D)
void php_rfc1867_register_constants(TSRMLS_D)
void zend_register_standard_constants(TSRMLS_D)
zend_ini_startup(TSRMLS_C);
/* {{{ void php_output_startup(void) * Set up module globals and initalize the conflict and reverse conflict hash tables */PHPAPI void php_output_startup(void)
static void php_load_zend_extension_cb(void *arg TSRMLS_DC)
REGISTER_MAIN_LONG_CONSTANT(\"UPLOAD_ERR_OK\
return sapi_cgibin_getenv((char *) \"HTTP_COOKIE\
/*Prepare search path
ZEND_API void gc_globals_ctor(TSRMLS_D)
zend_startup_extensions_mechanism();
EG(bailout) = NULL;EG(error_reporting) = E_ALL & ~E_NOTICE;EG(active_symbol_table) = NULL;PG(header_is_being_sent) = 0; SG(request_info).headers_only = 0; SG(request_info).argv0 = NULL;SG(request_info).argc=0;SG(request_info).argv=(char **)NULL;PG(connection_status) = PHP_CONNECTION_NORMAL;PG(during_request_startup) = 0; PG(last_error_message) = NULL;PG(last_error_file) = NULL;PG(last_error_lineno) = 0; EG(error_handling) = EH_NORMAL;EG(exception_class) = NULL;PG(disable_functions) = NULL;PG(disable_classes) = NULL;EG(exception) = NULL;EG(objects_store).object_buckets = NULL;
int module_number = 0;REGISTER_INI_ENTRIES();
//use dlopen to load the .so file/* load dynamic symbol */ handle = DL_LOAD(libpath);
/* Initialize module globals */if (module-globals_size) {if (module-globals_ctor) {module-globals_ctor(module-globals_ptr TSRMLS_CC);
ZEND_API int zend_startup_modules(TSRMLS_D)
gc_globals_ctor(TSRMLS_C);
SG(request_info).content_type_dup = content_type;
/* load and startup extensions compiled as shared objects (aka DLLs) as requested by php.ini entriestheese are loaded after initialization of internal extensions as extensions *might* rely on things from ext/standard which is always an internal extension and to be initialized ahead of all other internalsphp_ini_register_extensions(TSRMLS_C);
start_memory_manager(TSRMLS_C);
Y
if (sapi_module.input_filter_init) {sapi_module.input_filter_init(TSRMLS_C);
zend_builtin_module.module_number = 0;zend_builtin_module.type = MODULE_PERSISTENT;return (EG(current_module) = zend_register_module_ex(&zend_builtin_module TSRMLS_CC)) == NULL ? FAILURE : SUCCESS;
if (sapi_module.activate) {sapi_module.activate(TSRMLS_C);
/* startup extensions statically compiled in */if (php_register_internal_extensions_func(TSRMLS_C) == FAILURE) {php_printf(\"Unable to start builtin modules\\");
ZEND_API int zend_startup_module_ex(zend_module_entry *module TSRMLS_DC)
//Form-based File Upload in HTMLphp_rfc1867_register_constants(TSRMLS_C);
php_output_startup();
if (extension-startup) {if (extension-startup(extension)!=SUCCESS) {return 1;zend_append_version_info(extension);
ZEND_API int zend_ini_startup(TSRMLS_D)
php_output_register_constants(TSRMLS_C);
static int sapi_cgi_activate(TSRMLS_D)
zuv.html_errors = 1;zuv.import_use_extension = \".php\";zend_utility_values zuv;zend_set_utility_values(&zuv);
zend_opcode_handlers = (opcode_handler_t*)labels;
virtual_cwd_startup(); /* Could use shutdown to free the main cwd but it would just slow it down for CGI */
/* initialize stream wrappers registry * (this uses configuration parameters from php.ini)if (php_init_stream_wrappers(module_number TSRMLS_CC) == FAILURE)
int zend_load_extension(const char *path)
if (read_bytes buflen) {SG(post_read) = 1; return read_bytes;
if (sapi_module.read_post) {
static inline void php_output_init_globals(zend_output_globals *G)
int php_startup_sapi_content_types(TSRMLS_D)
php_startup_sapi_content_types(TSRMLS_C);
module_initialized = 1;
zend_llist_destroy(&SG(sapi_headers).headers);
/* If SAPI does not want to ignore all ini files OR an overriding file/path is given.* This allows disabling scanning for ini files in the PHP_CONFIG_FILE_SCAN_DIR but still* load an optional ini file. */if (!sapi_module.php_ini_ignore || sapi_module.php_ini_path_override) {
ZEND_API zend_mm_heap *zend_mm_startup(void)
/* start Zend extensions */ zend_startup_extensions();
/* Check for PHP_INI_SCAN_DIR environment variable to override/set config file scan directory */php_ini_scanned_path = getenv(\"PHP_INI_SCAN_DIR\");if (!php_ini_scanned_path) { /* Or fall back using possible --with-config-file-scan-dir setting (defaults to empty string!) */php_ini_scanned_path = PHP_CONFIG_FILE_SCAN_DIR;php_ini_scanned_path_len = strlen(php_ini_scanned_path);
/* Scan and parse any .ini files found in scan path if path not empty. */if (!sapi_module.php_ini_ignore && php_ini_scanned_path_len) {
zend_register_auto_global(\"GLOBALS\
PG(php_binary) = binary_location;
return zend_register_module_ex(module TSRMLS_CC);
fcgi_request *request = (fcgi_request*) SG(server_context);char *request_body_filename = sapi_cgibin_getenv((char *) \"REQUEST_BODY_FILE\
REGISTER_MAIN_LONG_CONSTANT(\"PHP_OUTPUT_HANDLER_START\
if ((SG(post_max_size) 0) && (SG(request_info).content_length SG(post_max_size))) {
N
zend_set_default_compile_time_values(TSRMLS_C);
php_output_direct = php_output_stdout;
alloc_globals-mm_heap = zend_mm_startup();
zend_register_standard_constants(TSRMLS_C);
//add the module in the .so file into module_registries global hash tableif ((module_entry = zend_register_module_ex(module_entry TSRMLS_CC)) == NULL) {
SG(server_context) = NULL; SG(request_info).request_method = NULL; SG(request_info).auth_digest = SG(request_info).auth_user = SG(request_info).auth_password = NULL; SG(request_info).content_type_dup = NULL;
/* Check module dependencies */if (module-deps) {
static void php_binary_init(TSRMLS_D)
zend_compile_file = compile_file;zend_execute_ex = execute_ex;zend_execute_internal = NULL;
SAPI_API void sapi_deactivate(TSRMLS_D)
ini_scanner_globals_ctor(&ini_scanner_globals TSRMLS_CC);
if (sapi_module.ini_defaults) {sapi_module.ini_defaults(&configuration_hash);
module_startup = 0;
PHPAPI int php_register_internal_extensions(TSRMLS_D)
static int zend_extension_startup(zend_extension *extension)
/* Set up utility functions and values */zend_error_cb = utility_functions-error_function;zend_printf = utility_functions-printf_function;zend_write = (zend_write_func_t) utility_functions-write_function;zend_fopen = utility_functions-fopen_function;
int zend_startup_builtin_functions(TSRMLS_D)
zend_register_auto_global(ZEND_STRL(\"_GET\
if (SG(sapi_started) && EG(in_execution)) {return FAILURE; sapi_module.default_post_reader = default_post_reader;
/* PATH_TRANSLATED should be defined at this stage but better safe than sorry :) */ if (!SG(request_info).path_translated) {return FAILURE;
ZEND_API zend_module_entry* zend_register_internal_module(zend_module_entry *module TSRMLS_DC)
zend_register_constant(&c TSRMLS_CC);
while (p-name) {
int php_startup_ticks(TSRMLS_D)
sapi_activate(TSRMLS_C);
if(sapi_module.default_post_reader) {sapi_module.default_post_reader(TSRMLS_C);
/* Register constants */REGISTER_MAIN_STRINGL_CONSTANT(\"PHP_VERSION\
php_stream_rewind(SG(request_info).request_body);
/* Disable realpath cache if an open_basedir is set */if (PG(open_basedir) && *PG(open_basedir)) {CWDG(realpath_cache_size_limit) = 0;
0 条评论
回复 删除
下一页