欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

PHP内核两大流程之启动PHP的核心代码段

程序员文章站 2022-06-23 14:52:55
step 1: start the sapi extern zend_module_entry php_apache_module; static int php_apache2_startup...
step 1: start the sapi

extern zend_module_entry php_apache_module;

static int php_apache2_startup(sapi_module_struct *sapi_module)
{
        if (php_module_startup(sapi_module, &php_apache_module, 1)==failure) {
                return failure;
        }
        return success;
}

step 2: start the php

int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_modules, uint num_additional_modules)
{
        zend_utility_functions zuf;
        zend_utility_values zuv;

	.....

	sapi_module = *sf;

	php_output_startup();

        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;
        zuf.message_handler = php_message_handler_for_zend;
        zuf.block_interruptions = sapi_module.block_interruptions;
        zuf.unblock_interruptions = sapi_module.unblock_interruptions;
        zuf.get_configuration_directive = php_get_configuration_directive_for_zend;
        zuf.ticks_function = php_run_ticks;
        zuf.on_timeout = php_on_timeout;
        zuf.stream_open_function = php_stream_open_for_zend;
        zuf.vspprintf_function = vspprintf;
        zuf.getenv_function = sapi_getenv;
        zuf.resolve_path_function = php_resolve_path_for_zend;
        zend_startup(&zuf, null tsrmls_cc);

	......

	gc_globals_ctor(tsrmls_c);

	......

        /* register php core ini entries */
        register_ini_entries();

        /* register zend ini entries */
        zend_register_standard_ini_entries(tsrmls_c);

        /* disable realpath cache if an open_basedir is set */
        if (pg(open_basedir) && *pg(open_basedir)) {
                cwdg(realpath_cache_size_limit) = 0;
        }

        /* initialize stream wrappers registry
         * (this uses configuration parameters from php.ini)
         */
        if (php_init_stream_wrappers(module_number tsrmls_cc) == failure)       {
                php_printf("php:  unable to initialize stream url wrappers.\n");
                return failure;
        }

        /* startup extensions staticly compiled in */
        if (php_register_internal_extensions_func(tsrmls_c) == failure) {
                php_printf("unable to start builtin modules\n");
                return failure;
        }

        /* start additional php extensions */
        php_register_extensions_bc(additional_modules, num_additional_modules tsrmls_cc);

        /* load and startup extensions compiled as shared objects (aka dlls)
           as requested by php.ini entries
           theese 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 internals
         */
        php_ini_register_extensions(tsrmls_c);
        zend_startup_modules(tsrmls_c);

        /* start zend extensions */
        zend_startup_extensions();

	.....
}

int zend_startup
(zend_utility_functions *utility_functions, char **extensions tsrmls_dc) /* {{{ */
{
        zend_compiler_globals *compiler_globals;
        zend_executor_globals *executor_globals;
	
	......

        zend_compile_file = compile_file;
        zend_execute_ex = execute_ex;
        zend_execute_internal = null;

        zend_init_opcodes_handlers();
	
	......
}