文章还没远远没写完,因为发现整个启动过程涉及太多东西了,慢慢写~慢慢更新...
------------------------------------------------------------------------------------------------------------------------
PHP可以以多种方式运行,例如作为apache一个模块mod_php5,cli,cgi,fastcgi,embed。但不管什么运行方式,它们都有一些共性的东西,例如,都有module init, request start, run... request end, module end这些基本过程,当然还有其它东西。PHP提供了一个给外部提供服务的接口,即:SAPI。
下面看下sapi模块的结构:
/** /PHP_5_4/main/SAPI.h */
struct _sapi_module_struct {
char *name;
char *pretty_name;
int (*startup)(struct _sapi_module_struct *sapi_module);
int (*shutdown)(struct _sapi_module_struct *sapi_module);
int (*activate)(TSRMLS_D);
int (*deactivate)(TSRMLS_D);
int (*ub_write)(const char *str, unsigned int str_length TSRMLS_DC);
void (*flush)(void *server_context);
struct stat *(*get_stat)(TSRMLS_D);
char *(*getenv)(char *name, size_t name_len TSRMLS_DC);
void (*sapi_error)(int type, const char *error_msg, ...);
int (*header_handler)(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC);
int (*send_headers)(sapi_headers_struct *sapi_headers TSRMLS_DC);
void (*send_header)(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC);
int (*read_post)(char *buffer, uint count_bytes TSRMLS_DC);
char *(*read_cookies)(TSRMLS_D);
void (*register_server_variables)(zval *track_vars_array TSRMLS_DC);
void (*log_message)(char *message TSRMLS_DC);
double (*get_request_time)(TSRMLS_D);
void (*terminate_process)(TSRMLS_D);
char *php_ini_path_override;
void (*block_interruptions)(void);
void (*unblock_interruptions)(void);
void (*default_post_reader)(TSRMLS_D);
void (*treat_data)(int arg, char *str, zval *destArray TSRMLS_DC);
char *executable_location;
int php_ini_ignore;
int php_ini_ignore_cwd; /* don't look for php.ini in the current directory */
int (*get_fd)(int *fd TSRMLS_DC);
int (*force_http_10)(TSRMLS_D);
int (*get_target_uid)(uid_t * TSRMLS_DC);
int (*get_target_gid)(gid_t * TSRMLS_DC);
unsigned int (*input_filter)(int arg, char *var, char **val, unsigned int val_len, unsigned int *new_val_len TSRMLS_DC);
void (*ini_defaults)(HashTable *configuration_hash);
int phpinfo_as_text;
char *ini_entries;
const zend_function_entry *additional_functions;
unsigned int (*input_filter_init)(TSRMLS_D);
};
1.作为apache一个模块运行
过程大概是这样的,apache对一个http请求有11个处理阶段,apache的扩展模块可以往这11个处理阶段注册一些钩子,apache对这些扩展的模块有个约定,也就是apache的模块结构,模块结构中指定一些接口可以进行注入。所以,在这个形式下,PHP就开发了一个模块,这个模块既实现了apache的模块结构,又使用了PHP的SAPI,这样,PHP就能作为apache的一个模块运行了。
/**这里先描述一下大概的过程
1.初始化SAPI
2.初始化zend_utility工具函数,包括错误处理、输入输出等。
3.启动zend引擎
{ 1.启动内存管理
2.初始化两个锁(字符串->doubule),strtod...这个还没搞清楚
3.初始化扩展列表
4.初始化多线程共享的工具函数,这里就跟zend_utility的函数一样
5.zend编译相关的句柄的初始化
6.设置zend版本信息
7.初始化"全局"的函数表(100)、类表(10)、"全局"变量表(8)、常量表(20)、模块注册表(50)和rsrc_list_destructor
8.初始化 zval_used_for_init 这个用来给别的zval初始化赋值用的
9.分配编译相关的资源
10.zend内部字符串处理相关的初始化 zend内置模块注册(包括内置的函数) zend内置常量注册 zend 的auto globals 即$_GLOBALS
11.初始化ini 配置指令
}
4.初始化executor_globals(执行环境的"全局"结构),php_core_globals(php环境的"全局"结构)、gc_globals(垃圾回收)以及SAPI的 request_info
5.本地化setlocale,获得时区tzset()
6.le_index_ptr(还没弄懂)
7.注册PHP的常量
8.php路径相关的初始化
9.注册PHP的一些与(ouput、rfc1867)相关的常量(怎么不放在第7步一起?Fuck!)
10.php ini的配置
11.注册php的ini entries以及zend的ini entries
12.初始化stream wrappers registry
13.搞一下php的logo......
14.注册PHP的全局变量即$_GET,$_POST,$_COOKIE,$_SERVER,$_REQUEST,$_FILES
15.启动SAPI的content types
16.注册内置的扩展
17.加载并启动注册的模块扩展
18.zend_collect_module_handlers。...不知道干啥
19.注册SAPI中的附加函数
20.禁用php.ini中指定的函数和类
21.检查弃用的配置指令
22.sapi_deactive钩子调用
23.关闭内存管理
24.处理与编译相关的interned_strings...怎么再最后干这事???
*/
/** /PHP_5_4/sapi/apache2handler/mod_php5.c
* 这个结构就是apache模块的结构体,最后一个成员 php_ap2_register_hook 就是钩子*/
AP_MODULE_DECLARE_DATA module php5_module = {
STANDARD20_MODULE_STUFF,
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, /* command apr_table_t */
php_ap2_register_hook /* register hooks */
};
/* /PHP_5_4/sapi/apache2handler/sapi_apache2.c */
//可以看到注册了四个钩子
void php_ap2_register_hook(apr_pool_t *p)
{
ap_hook_pre_config(php_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_post_config(php_apache_server_startup, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_handler(php_handler, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_child_init(php_apache_child_init, NULL, NULL, APR_HOOK_MIDDLE);
}
/*我们看看启动的那个钩子 php_apache_server_startup
* apache2_sapi_module是 上面提到过的SAPI的结构
* 大体的几步:
tsrm_startup(1, 1, 0, NULL); //多线程相关
sapi_startup(&apache2_sapi_module); //SAPI初始化
apache2_sapi_module.startup(&apache2_sapi_module); //启动SAPI,用到的启动函数是这个php_apache2_startup
apr_pool_cleanup_register(pconf, NULL, php_apache_server_shutdown, apr_pool_cleanup_null);
php_apache_add_version(pconf);
*/
php_apache_server_startup(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
{
void *data = NULL;
const char *userdata_key = "apache2hook_post_config";
/* Apache will load, unload and then reload a DSO module. This
* prevents us from starting PHP until the second load. */
apr_pool_userdata_get(&data, userdata_key, s->process->pool);
if (data == NULL) {
/* We must use set() here and *not* setn(), otherwise the
* static string pointed to by userdata_key will be mapped
* to a different location when the DSO is reloaded and the
* pointers won't match, causing get() to return NULL when
* we expected it to return non-NULL. */
apr_pool_userdata_set((const void *)1, userdata_key, apr_pool_cleanup_null, s->process->pool);
return OK;
}
/* Set up our overridden path. */
if (apache2_php_ini_path_override) {
apache2_sapi_module.php_ini_path_override = apache2_php_ini_path_override;
}
#ifdef ZTS
tsrm_startup(1, 1, 0, NULL);
#endif
sapi_startup(&apache2_sapi_module);
apache2_sapi_module.startup(&apache2_sapi_module);
apr_pool_cleanup_register(pconf, NULL, php_apache_server_shutdown, apr_pool_cleanup_null);
php_apache_add_version(pconf);
return OK;
}
/** /PHP_5_4/sapi/apache2handler/sapi_apache2.c */
static sapi_module_struct apache2_sapi_module = {
"apache2handler",
"Apache 2.0 Handler",
php_apache2_startup, /* startup */
php_module_shutdown_wrapper, /* shutdown */
NULL, /* activate */
NULL, /* deactivate */
php_apache_sapi_ub_write, /* unbuffered write */
php_apache_sapi_flush, /* flush */
php_apache_sapi_get_stat, /* get uid */
php_apache_sapi_getenv, /* getenv */
php_error, /* error handler */
php_apache_sapi_header_handler, /* header handler */
php_apache_sapi_send_headers, /* send headers handler */
NULL, /* send header handler */
php_apache_sapi_read_post, /* read POST data */
php_apache_sapi_read_cookies, /* read Cookies */
php_apache_sapi_register_variables,
php_apache_sapi_log_message, /* Log message */
php_apache_sapi_get_request_time, /* Request Time */
NULL, /* Child Terminate */
STANDARD_SAPI_MODULE_PROPERTIES
};
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;
}
/** php_module_startup这个行数相当长!
/PHP_5_4/main/main.c */
/* {{{ php_module_startup
*/
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;
int retval = SUCCESS, module_number=0; /* for REGISTER_INI_ENTRIES() */
char *php_os;
zend_module_entry *module;
#ifdef ZTS
zend_executor_globals *executor_globals;
void ***tsrm_ls;
php_core_globals *core_globals;
#endif
#if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK))
WORD wVersionRequested = MAKEWORD(2, 0);
WSADATA wsaData;
#endif
#ifdef PHP_WIN32
php_os = "WINNT";
#if _MSC_VER >= 1400
old_invalid_parameter_handler =
_set_invalid_parameter_handler(dummy_invalid_parameter_handler);
if (old_invalid_parameter_handler != NULL) {
_set_invalid_parameter_handler(old_invalid_parameter_handler);
}
/* Disable the message box for assertions.*/
_CrtSetReportMode(_CRT_ASSERT, 0);
#endif
#else
php_os=PHP_OS;
#endif
#ifdef ZTS
tsrm_ls = ts_resource(0);
#endif
#ifdef PHP_WIN32
php_win32_init_rng_lock();
#endif
module_shutdown = 0;
module_startup = 1;
sapi_initialize_empty_request(TSRMLS_C);
sapi_activate(TSRMLS_C);
if (module_initialized) {
return SUCCESS;
}
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);
#ifdef ZTS
executor_globals = ts_resource(executor_globals_id);
ts_allocate_id(&core_globals_id, sizeof(php_core_globals), (ts_allocate_ctor) core_globals_ctor, (ts_allocate_dtor) core_globals_dtor);
core_globals = ts_resource(core_globals_id);
#ifdef PHP_WIN32
ts_allocate_id(&php_win32_core_globals_id, sizeof(php_win32_core_globals), (ts_allocate_ctor) php_win32_core_globals_ctor, (ts_allocate_dtor) php_win32_core_globals_dtor);
#endif
#else
php_startup_ticks(TSRMLS_C);
#endif
gc_globals_ctor(TSRMLS_C);
#ifdef PHP_WIN32
{
OSVERSIONINFOEX *osvi = &EG(windows_version_info);
ZeroMemory(osvi, sizeof(OSVERSIONINFOEX));
osvi->dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
if( !GetVersionEx((OSVERSIONINFO *) osvi)) {
php_printf("\nGetVersionEx unusable. %d\n", GetLastError());
return FAILURE;
}
}
#endif
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;
#if HAVE_SETLOCALE
setlocale(LC_CTYPE, "");
zend_update_current_locale();
#endif
#if HAVE_TZSET
tzset();
#endif
#if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK))
/* start up winsock services */
if (WSAStartup(wVersionRequested, &wsaData) != 0) {
php_printf("\nwinsock.dll unusable. %d\n", WSAGetLastError());
return FAILURE;
}
#endif
le_index_ptr = zend_register_list_destructors_ex(NULL, NULL, "index pointer", 0);
/* Register constants */
REGISTER_MAIN_STRINGL_CONSTANT("PHP_VERSION", PHP_VERSION, sizeof(PHP_VERSION)-1, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_LONG_CONSTANT("PHP_MAJOR_VERSION", PHP_MAJOR_VERSION, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_LONG_CONSTANT("PHP_MINOR_VERSION", PHP_MINOR_VERSION, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_LONG_CONSTANT("PHP_RELEASE_VERSION", PHP_RELEASE_VERSION, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_STRINGL_CONSTANT("PHP_EXTRA_VERSION", PHP_EXTRA_VERSION, sizeof(PHP_EXTRA_VERSION) - 1, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_LONG_CONSTANT("PHP_VERSION_ID", PHP_VERSION_ID, CONST_PERSISTENT | CONST_CS);
#ifdef ZTS
REGISTER_MAIN_LONG_CONSTANT("PHP_ZTS", 1, CONST_PERSISTENT | CONST_CS);
#else
REGISTER_MAIN_LONG_CONSTANT("PHP_ZTS", 0, CONST_PERSISTENT | CONST_CS);
#endif
REGISTER_MAIN_LONG_CONSTANT("PHP_DEBUG", PHP_DEBUG, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_STRINGL_CONSTANT("PHP_OS", php_os, strlen(php_os), CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_STRINGL_CONSTANT("PHP_SAPI", sapi_module.name, strlen(sapi_module.name), CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_STRINGL_CONSTANT("DEFAULT_INCLUDE_PATH", PHP_INCLUDE_PATH, sizeof(PHP_INCLUDE_PATH)-1, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_STRINGL_CONSTANT("PEAR_INSTALL_DIR", PEAR_INSTALLDIR, sizeof(PEAR_INSTALLDIR)-1, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_STRINGL_CONSTANT("PEAR_EXTENSION_DIR", PHP_EXTENSION_DIR, sizeof(PHP_EXTENSION_DIR)-1, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_STRINGL_CONSTANT("PHP_EXTENSION_DIR", PHP_EXTENSION_DIR, sizeof(PHP_EXTENSION_DIR)-1, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_STRINGL_CONSTANT("PHP_PREFIX", PHP_PREFIX, sizeof(PHP_PREFIX)-1, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINDIR", PHP_BINDIR, sizeof(PHP_BINDIR)-1, CONST_PERSISTENT | CONST_CS);
#ifndef PHP_WIN32
REGISTER_MAIN_STRINGL_CONSTANT("PHP_MANDIR", PHP_MANDIR, sizeof(PHP_MANDIR)-1, CONST_PERSISTENT | CONST_CS);
#endif
REGISTER_MAIN_STRINGL_CONSTANT("PHP_LIBDIR", PHP_LIBDIR, sizeof(PHP_LIBDIR)-1, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_STRINGL_CONSTANT("PHP_DATADIR", PHP_DATADIR, sizeof(PHP_DATADIR)-1, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_STRINGL_CONSTANT("PHP_SYSCONFDIR", PHP_SYSCONFDIR, sizeof(PHP_SYSCONFDIR)-1, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_STRINGL_CONSTANT("PHP_LOCALSTATEDIR", PHP_LOCALSTATEDIR, sizeof(PHP_LOCALSTATEDIR)-1, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_STRINGL_CONSTANT("PHP_CONFIG_FILE_PATH", PHP_CONFIG_FILE_PATH, strlen(PHP_CONFIG_FILE_PATH), CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_STRINGL_CONSTANT("PHP_CONFIG_FILE_SCAN_DIR", PHP_CONFIG_FILE_SCAN_DIR, sizeof(PHP_CONFIG_FILE_SCAN_DIR)-1, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_STRINGL_CONSTANT("PHP_SHLIB_SUFFIX", PHP_SHLIB_SUFFIX, sizeof(PHP_SHLIB_SUFFIX)-1, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_STRINGL_CONSTANT("PHP_EOL", PHP_EOL, sizeof(PHP_EOL)-1, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_LONG_CONSTANT("PHP_MAXPATHLEN", MAXPATHLEN, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_LONG_CONSTANT("PHP_INT_MAX", LONG_MAX, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_LONG_CONSTANT("PHP_INT_SIZE", sizeof(long), CONST_PERSISTENT | CONST_CS);
#ifdef PHP_WIN32
REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_MAJOR", EG(windows_version_info).dwMajorVersion, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_MINOR", EG(windows_version_info).dwMinorVersion, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_BUILD", EG(windows_version_info).dwBuildNumber, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_PLATFORM", EG(windows_version_info).dwPlatformId, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_SP_MAJOR", EG(windows_version_info).wServicePackMajor, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_SP_MINOR", EG(windows_version_info).wServicePackMinor, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_SUITEMASK", EG(windows_version_info).wSuiteMask, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_PRODUCTTYPE", EG(windows_version_info).wProductType, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_NT_DOMAIN_CONTROLLER", VER_NT_DOMAIN_CONTROLLER, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_NT_SERVER", VER_NT_SERVER, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_NT_WORKSTATION", VER_NT_WORKSTATION, CONST_PERSISTENT | CONST_CS);
#endif
php_binary_init(TSRMLS_C);
if (PG(php_binary)) {
REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINARY", PG(php_binary), strlen(PG(php_binary)), CONST_PERSISTENT | CONST_CS);
} else {
REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINARY", "", 0, CONST_PERSISTENT | CONST_CS);
}
php_output_register_constants(TSRMLS_C);
php_rfc1867_register_constants(TSRMLS_C);
/* this will read in php.ini, set up the configuration parameters,
load zend extensions and register php function extensions
to be loaded later */
if (php_init_config(TSRMLS_C) == FAILURE) {
return FAILURE;
}
/* 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;
}
/* initialize registry for images to be used in phpinfo()
(this uses configuration parameters from php.ini)
*/
if (php_init_info_logos() == FAILURE) {
php_printf("PHP: Unable to initialize info phpinfo logos.\n");
return FAILURE;
}
zuv.html_errors = 1;
zuv.import_use_extension = ".php";
php_startup_auto_globals(TSRMLS_C);
zend_set_utility_values(&zuv);
php_startup_sapi_content_types(TSRMLS_C);
/* 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(&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();
zend_collect_module_handlers(TSRMLS_C);
/* register additional functions */
if (sapi_module.additional_functions) {
if (zend_hash_find(&module_registry, "standard", sizeof("standard"), (void**)&module)==SUCCESS) {
EG(current_module) = module;
zend_register_functions(NULL, sapi_module.additional_functions, NULL, MODULE_PERSISTENT TSRMLS_CC);
EG(current_module) = NULL;
}
}
/* disable certain classes and functions as requested by php.ini */
php_disable_functions(TSRMLS_C);
php_disable_classes(TSRMLS_C);
/* make core report what it should */
if (zend_hash_find(&module_registry, "core", sizeof("core"), (void**)&module)==SUCCESS) {
module->version = PHP_VERSION;
module->info_func = PHP_MINFO(php_core);
}
#ifdef PHP_WIN32
/* Disable incompatible functions for the running platform */
if (php_win32_disable_functions(TSRMLS_C) == FAILURE) {
php_printf("Unable to disable unsupported functions\n");
return FAILURE;
}
#endif
#ifdef ZTS
zend_post_startup(TSRMLS_C);
#endif
module_initialized = 1;
/* Check for deprecated directives */
/* NOTE: If you add anything here, remember to add it to Makefile.global! */
{
struct {
const long error_level;
const char *phrase;
const char *directives[16]; /* Remember to change this if the number of directives change */
} directives[2] = {
{
E_DEPRECATED,
"Directive '%s' is deprecated in PHP 5.3 and greater",
{
NULL
}
},
{
E_CORE_ERROR,
"Directive '%s' is no longer available in PHP",
{
"allow_call_time_pass_reference",
"define_syslog_variables",
"highlight.bg",
"magic_quotes_gpc",
"magic_quotes_runtime",
"magic_quotes_sybase",
"register_globals",
"register_long_arrays",
"safe_mode",
"safe_mode_gid",
"safe_mode_include_dir",
"safe_mode_exec_dir",
"safe_mode_allowed_env_vars",
"safe_mode_protected_env_vars",
"zend.ze1_compatibility_mode",
NULL
}
}
};
unsigned int i;
zend_try {
/* 2 = Count of deprecation structs */
for (i = 0; i < 2; i++) {
const char **p = directives[i].directives;
while(*p) {
long value;
if (cfg_get_long((char*)*p, &value) == SUCCESS && value) {
zend_error(directives[i].error_level, directives[i].phrase, *p);
}
++p;
}
}
} zend_catch {
retval = FAILURE;
} zend_end_try();
}
sapi_deactivate(TSRMLS_C);
module_startup = 0;
shutdown_memory_manager(1, 0 TSRMLS_CC);
zend_interned_strings_snapshot(TSRMLS_C);
/* we're done */
return retval;
}
/* }}} */