static apr_status_t php_apache_server_shutdown(void *tmp) { apache2_sapi_module.shutdown(&apache2_sapi_module); sapi_shutdown(); #ifdef ZTS tsrm_shutdown(); #endif return APR_SUCCESS; }
EMBED_SAPI_API void php_embed_shutdown(void) { php_request_shutdown((void *) 0); php_module_shutdown(); sapi_shutdown(); #ifdef ZTS tsrm_shutdown(); #endif if (php_embed_module.ini_entries) { free(php_embed_module.ini_entries); php_embed_module.ini_entries = NULL; } }
static void php_ns_server_shutdown(void *context) { php_ns_context *ctx = (php_ns_context *) context; ctx->sapi_module->shutdown(ctx->sapi_module); sapi_shutdown(); tsrm_shutdown(); free(ctx->ns_module); free(ctx->ns_server); free(ctx); }
int phpShutdown() { if ( php_embed_module.php_ini_path_override ) { free( php_embed_module.php_ini_path_override ); } if ( php_embed_module.ini_entries ) { free( php_embed_module.ini_entries ); } php_module_shutdown( TSRMLS_C ); sapi_shutdown(); return 0; }
int main(int argc, char *argv[]) #endif { #ifdef PHP_CLI_WIN32_NO_CONSOLE int argc = __argc; char **argv = __argv; #endif int c; int exit_status = SUCCESS; int module_started = 0, sapi_started = 0; char *php_optarg = NULL; int php_optind = 1, use_extended_info = 0; char *ini_path_override = NULL; char *ini_entries = NULL; int ini_entries_len = 0; int ini_ignore = 0; sapi_module_struct *sapi_module = &cli_sapi_module; /* * Do not move this initialization. It needs to happen before argv is used * in any way. */ argv = save_ps_args(argc, argv); cli_sapi_module.additional_functions = additional_functions; #if defined(PHP_WIN32) && defined(_DEBUG) && defined(PHP_WIN32_DEBUG_HEAP) { int tmp_flag; _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE); _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); tmp_flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); tmp_flag |= _CRTDBG_DELAY_FREE_MEM_DF; tmp_flag |= _CRTDBG_LEAK_CHECK_DF; _CrtSetDbgFlag(tmp_flag); } #endif #ifdef HAVE_SIGNAL_H #if defined(SIGPIPE) && defined(SIG_IGN) signal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE in standalone mode so that sockets created via fsockopen() don't kill PHP if the remote site closes it. in apache|apxs mode apache does that for us! [email protected] 20000419 */ #endif #endif #ifdef ZTS tsrm_startup(1, 1, 0, NULL); (void)ts_resource(0); ZEND_TSRMLS_CACHE_UPDATE(); #endif #ifdef ZEND_SIGNALS zend_signal_startup(); #endif #ifdef PHP_WIN32 _fmode = _O_BINARY; /*sets default for file streams to binary */ setmode(_fileno(stdin), O_BINARY); /* make the stdio mode be binary */ setmode(_fileno(stdout), O_BINARY); /* make the stdio mode be binary */ setmode(_fileno(stderr), O_BINARY); /* make the stdio mode be binary */ #endif while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2))!=-1) { switch (c) { case 'c': if (ini_path_override) { free(ini_path_override); } ini_path_override = strdup(php_optarg); break; case 'n': ini_ignore = 1; break; case 'd': { /* define ini entries on command line */ int len = (int)strlen(php_optarg); char *val; if ((val = strchr(php_optarg, '='))) { val++; if (!isalnum(*val) && *val != '"' && *val != '\'' && *val != '\0') { ini_entries = realloc(ini_entries, ini_entries_len + len + sizeof("\"\"\n\0")); memcpy(ini_entries + ini_entries_len, php_optarg, (val - php_optarg)); ini_entries_len += (int)(val - php_optarg); memcpy(ini_entries + ini_entries_len, "\"", 1); ini_entries_len++; memcpy(ini_entries + ini_entries_len, val, len - (val - php_optarg)); ini_entries_len += len - (int)(val - php_optarg); memcpy(ini_entries + ini_entries_len, "\"\n\0", sizeof("\"\n\0")); ini_entries_len += sizeof("\n\0\"") - 2; } else { ini_entries = realloc(ini_entries, ini_entries_len + len + sizeof("\n\0")); memcpy(ini_entries + ini_entries_len, php_optarg, len); memcpy(ini_entries + ini_entries_len + len, "\n\0", sizeof("\n\0")); ini_entries_len += len + sizeof("\n\0") - 2; } } else { ini_entries = realloc(ini_entries, ini_entries_len + len + sizeof("=1\n\0")); memcpy(ini_entries + ini_entries_len, php_optarg, len); memcpy(ini_entries + ini_entries_len + len, "=1\n\0", sizeof("=1\n\0")); ini_entries_len += len + sizeof("=1\n\0") - 2; } break; } #ifndef PHP_CLI_WIN32_NO_CONSOLE case 'S': sapi_module = &cli_server_sapi_module; cli_server_sapi_module.additional_functions = server_additional_functions; break; #endif case 'h': /* help & quit */ case '?': php_cli_usage(argv[0]); goto out; case 'i': case 'v': case 'm': sapi_module = &cli_sapi_module; goto exit_loop; case 'e': /* enable extended info output */ use_extended_info = 1; break; } } exit_loop: sapi_module->ini_defaults = sapi_cli_ini_defaults; sapi_module->php_ini_path_override = ini_path_override; sapi_module->phpinfo_as_text = 1; sapi_module->php_ini_ignore_cwd = 1; sapi_startup(sapi_module); sapi_started = 1; sapi_module->php_ini_ignore = ini_ignore; sapi_module->executable_location = argv[0]; if (sapi_module == &cli_sapi_module) { if (ini_entries) { ini_entries = realloc(ini_entries, ini_entries_len + sizeof(HARDCODED_INI)); memmove(ini_entries + sizeof(HARDCODED_INI) - 2, ini_entries, ini_entries_len + 1); memcpy(ini_entries, HARDCODED_INI, sizeof(HARDCODED_INI) - 2); } else { ini_entries = malloc(sizeof(HARDCODED_INI)); memcpy(ini_entries, HARDCODED_INI, sizeof(HARDCODED_INI)); } ini_entries_len += sizeof(HARDCODED_INI) - 2; } sapi_module->ini_entries = ini_entries; /* startup after we get the above ini override se we get things right */ if (sapi_module->startup(sapi_module) == FAILURE) { /* there is no way to see if we must call zend_ini_deactivate() * since we cannot check if EG(ini_directives) has been initialised * because the executor's constructor does not set initialize it. * Apart from that there seems no need for zend_ini_deactivate() yet. * So we goto out_err.*/ exit_status = 1; goto out; } module_started = 1; /* -e option */ if (use_extended_info) { CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO; } zend_first_try { #ifndef PHP_CLI_WIN32_NO_CONSOLE if (sapi_module == &cli_sapi_module) { #endif exit_status = do_cli(argc, argv); #ifndef PHP_CLI_WIN32_NO_CONSOLE } else { exit_status = do_cli_server(argc, argv); } #endif } zend_end_try(); out: if (ini_path_override) { free(ini_path_override); } if (ini_entries) { free(ini_entries); } if (module_started) { php_module_shutdown(); } if (sapi_started) { sapi_shutdown(); } #ifdef ZTS tsrm_shutdown(); #endif /* * Do not move this de-initialization. It needs to happen right before * exiting. */ cleanup_ps_args(argv); exit(exit_status); }
void webjames_php_shutdown(void) /*called when WebJames is about to quit*/ { sapi_module.shutdown(&sapi_module); sapi_shutdown(); }
/* {{{ main */ int main(int argc, char *argv[]) { char *sock = NULL; int dofork = 0; int exit_status = SUCCESS; int c; /* temporary locals */ int orig_optind=ap_php_optind; char *orig_optarg=ap_php_optarg; int interactive=0; char *param_error=NULL; /* end of temporary locals */ void ***tsrm_ls; #ifdef HAVE_SIGNAL_H #if defined(SIGPIPE) && defined(SIG_IGN) signal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE in standalone mode so that sockets created via fsockopen() don't kill PHP if the remote site closes it. in apache|apxs mode apache does that for us! [email protected] 20000419 */ #endif #endif tsrm_startup(1, 1, 0, NULL); tsrm_ls = ts_resource(0); sapi_startup(&milter_sapi_module); while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) { switch (c) { case 'c': milter_sapi_module.php_ini_path_override = strdup(ap_php_optarg); break; case 'n': milter_sapi_module.php_ini_ignore = 1; break; } } ap_php_optind = orig_optind; ap_php_optarg = orig_optarg; milter_sapi_module.executable_location = argv[0]; sapi_module.startup(&milter_sapi_module); zend_first_try { while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) { switch (c) { case '?': php_output_tearup(); SG(headers_sent) = 1; php_milter_usage(argv[0]); php_output_teardown(); exit(1); break; } } ap_php_optind = orig_optind; ap_php_optarg = orig_optarg; /* Set some CLI defaults */ SG(options) |= SAPI_OPTION_NO_CHDIR; zend_alter_ini_entry("html_errors", 12, "0", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); zend_alter_ini_entry("max_execution_time", 19, "0", 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); zend_uv.html_errors = 0; /* tell the engine we're in non-html mode */ while ((c = ap_php_getopt(argc, argv, OPTSTRING)) != -1) { switch (c) { case 'a': /* interactive mode */ printf("Interactive mode enabled\n\n"); interactive=1; break; case 'C': /* don't chdir to the script directory */ /* This is default so NOP */ break; case 'd': /* define ini entries on command line */ define_command_line_ini_entry(ap_php_optarg); break; case 'D': /* daemon */ dofork = 1; break; case 'e': /* enable extended info output */ CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO; break; case 'f': /* parse file */ filename = ap_php_optarg; break; case 'h': /* help & quit */ case '?': php_output_tearup(); SG(headers_sent) = 1; php_milter_usage(argv[0]); php_output_teardown(); exit(1); break; case 'p': /* socket */ sock = strdup(ap_php_optarg); break; case 'v': /* show php version & quit */ if (php_request_startup()==FAILURE) { zend_ini_deactivate(); php_module_shutdown(); sapi_shutdown(); tsrm_shutdown(); exit(1); } SG(headers_sent) = 1; SG(request_info).no_headers = 1; php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) 1997-2014 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version()); php_output_teardown(); exit(1); break; case 'V': /* verbose */ flag_debug = atoi(ap_php_optarg); break; case 'z': /* load extension file */ zend_load_extension(ap_php_optarg); break; default: break; } } if (param_error) { SG(headers_sent) = 1; SG(request_info).no_headers = 1; PUTS(param_error); exit(1); } /* only set script_file if not set already and not in direct mode and not at end of parameter list */ if (argc > ap_php_optind && !filename) { filename=argv[ap_php_optind]; ap_php_optind++; } /* check if file exists, exit else */ if (dofork) { switch(fork()) { case -1: /* Uh-oh, we have a problem forking. */ fprintf(stderr, "Uh-oh, couldn't fork!\n"); exit(errno); break; case 0: /* Child */ break; default: /* Parent */ exit(0); } } if (sock) { struct stat junk; if (stat(sock,&junk) == 0) unlink(sock); } openlog("php-milter", LOG_PID, LOG_MAIL); if ((exit_status = mlfi_init())) { syslog(1, "mlfi_init failed."); closelog(); goto err; } smfi_setconn(sock); if (smfi_register(smfilter) == MI_FAILURE) { syslog(1, "smfi_register failed."); fprintf(stderr, "smfi_register failed\n"); closelog(); goto err; } else { exit_status = smfi_main(); } closelog(); if (milter_sapi_module.php_ini_path_override) { free(milter_sapi_module.php_ini_path_override); } } zend_catch { exit_status = EG(exit_status); } zend_end_try(); err: php_module_shutdown(); sapi_shutdown(); tsrm_shutdown(); exit(exit_status); }
static void fpm_php_cleanup(int which, void *arg) /* {{{ */ { php_module_shutdown(); sapi_shutdown(); }