int MaPhp4HandlerService::stop() { TSRMLS_FETCH(); php_module_shutdown(TSRMLS_C); tsrm_shutdown(); return 0; }
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; } }
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); }
static int cli_main( int argc, char * argv[] ) { static const char * ini_defaults[] = { "report_zend_debug", "0", "display_errors", "1", "register_argc_argv", "1", "html_errors", "0", "implicit_flush", "1", "output_buffering", "0", "max_execution_time", "0", "max_input_time", "-1", NULL }; const char ** ini; char ** p = &argv[1]; char ** argend= &argv[argc]; int ret = -1; int c; #if PHP_MAJOR_VERSION >= 7 zend_string * psKey; #endif lsapi_mode = 0; /* enter CLI mode */ #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 zend_first_try { SG(server_context) = (void *) 1; zend_uv.html_errors = 0; /* tell the engine we're in non-html mode */ CG(in_compilation) = 0; /* not initialized but needed for several options */ SG(options) |= SAPI_OPTION_NO_CHDIR; #if PHP_MAJOR_VERSION < 7 EG(uninitialized_zval_ptr) = NULL; #endif for( ini = ini_defaults; *ini; ini+=2 ) { #if PHP_MAJOR_VERSION >= 7 psKey = zend_string_init(*ini, strlen( *ini ), 1); zend_alter_ini_entry_chars(psKey, (char *)*(ini+1), strlen( *(ini+1) ), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); zend_string_release(psKey); #else zend_alter_ini_entry( (char *)*ini, strlen( *ini )+1, (char *)*(ini+1), strlen( *(ini+1) ), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); #endif } while (( p < argend )&&(**p == '-' )) { c = *((*p)+1); ++p; switch( c ) { case 'q': break; case 'i': if (php_request_startup() != FAILURE) { php_print_info(0xFFFFFFFF); #ifdef PHP_OUTPUT_NEWAPI php_output_end_all(); #else php_end_ob_buffers(1); #endif php_request_shutdown( NULL ); ret = 0; } break; case 'v': if (php_request_startup() != FAILURE) { #if ZEND_DEBUG php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) 1997-2018 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version()); #else php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) 1997-2018 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version()); #endif #ifdef PHP_OUTPUT_NEWAPI php_output_end_all(); #else php_end_ob_buffers(1); #endif php_request_shutdown( NULL ); ret = 0; } break; case 'c': ++p; /* fall through */ case 's': break; case 'l': source_highlight = 2; break; case 'h': case '?': default: cli_usage(); ret = 0; break; } } if ( ret == -1 ) { if ( *p ) { zend_file_handle file_handle; memset(&file_handle, 0, sizeof(file_handle)); file_handle.type = ZEND_HANDLE_FP; file_handle.handle.fp = VCWD_FOPEN(*p, "rb"); if ( file_handle.handle.fp ) { script_filename = *p; php_self = *p; SG(request_info).path_translated = estrdup(*p); SG(request_info).argc = argc - (p - argv); SG(request_info).argv = p; if (php_request_startup() == FAILURE ) { fclose( file_handle.handle.fp ); ret = 2; } else { if (source_highlight == 1) { zend_syntax_highlighter_ini syntax_highlighter_ini; php_get_highlight_struct(&syntax_highlighter_ini); highlight_file(SG(request_info).path_translated, &syntax_highlighter_ini); } else if (source_highlight == 2) { file_handle.filename = *p; file_handle.free_filename = 0; file_handle.opened_path = NULL; ret = php_lint_script(&file_handle); if (ret==SUCCESS) { zend_printf("No syntax errors detected in %s\n", file_handle.filename); } else { zend_printf("Errors parsing %s\n", file_handle.filename); } } else { file_handle.filename = *p; file_handle.free_filename = 0; file_handle.opened_path = NULL; php_execute_script(&file_handle); ret = EG(exit_status); } php_request_shutdown( NULL ); } } else { php_printf("Could not open input file: %s.\n", *p); } } else { cli_usage(); } } }zend_end_try(); php_module_shutdown(); #ifdef ZTS tsrm_shutdown(); #endif return ret; }
int main( int argc, char * argv[] ) { int ret; int bindFd; char * php_ini_path = NULL; char * php_bind = NULL; int n; int climode = 0; struct timeval tv_req_begin; struct timeval tv_req_end; int slow_script_msec = 0; char time_buf[40]; #ifdef HAVE_SIGNAL_H #if defined(SIGPIPE) && defined(SIG_IGN) signal(SIGPIPE, SIG_IGN); #endif #endif #ifdef ZTS tsrm_startup(1, 1, 0, NULL); #endif zend_signal_startup(); if (argc > 1 ) { if ( parse_opt( argc, argv, &climode, &php_ini_path, &php_bind ) == -1 ) { return 1; } } if ( climode ) { lsapi_sapi_module.phpinfo_as_text = 1; } else { setArgv0(argc, argv ); } sapi_startup(&lsapi_sapi_module); #ifdef ZTS compiler_globals = ts_resource(compiler_globals_id); executor_globals = ts_resource(executor_globals_id); core_globals = ts_resource(core_globals_id); sapi_globals = ts_resource(sapi_globals_id); tsrm_ls = ts_resource(0); SG(request_info).path_translated = NULL; #endif lsapi_sapi_module.executable_location = argv[0]; /* Initialize from environment variables before processing command-line * options: the latter override the former. */ init_sapi_from_env(&lsapi_sapi_module); if ( ignore_php_ini ) lsapi_sapi_module.php_ini_ignore = 1; if ( php_ini_path ) { lsapi_sapi_module.php_ini_path_override = php_ini_path; } lsapi_sapi_module.ini_defaults = sapi_lsapi_ini_defaults; if (php_module_startup(&lsapi_sapi_module, &litespeed_module_entry, 1) == FAILURE) { #ifdef ZTS tsrm_shutdown(); #endif return FAILURE; } if ( climode ) { return cli_main(argc, argv); } if ( php_bind ) { bindFd = LSAPI_CreateListenSock( php_bind, 10 ); if ( bindFd == -1 ) { fprintf( stderr, "Failed to bind socket [%s]: %s\n", php_bind, strerror( errno ) ); exit( 2 ); } if ( bindFd != 0 ) { dup2( bindFd, 0 ); close( bindFd ); } } LSAPI_Init(); LSAPI_Init_Env_Parameters( NULL ); lsapi_mode = 1; slow_script_msec = LSAPI_Get_Slow_Req_Msecs(); if ( php_bind ) { LSAPI_No_Check_ppid(); free( php_bind ); php_bind = NULL; } while( LSAPI_Prefork_Accept_r( &g_req ) >= 0 ) { if ( slow_script_msec ) { gettimeofday( &tv_req_begin, NULL ); } ret = processReq(); if ( slow_script_msec ) { gettimeofday( &tv_req_end, NULL ); n = ((long) tv_req_end.tv_sec - tv_req_begin.tv_sec ) * 1000 + (tv_req_end.tv_usec - tv_req_begin.tv_usec) / 1000; if ( n > slow_script_msec ) { strftime( time_buf, 30, "%d/%b/%Y:%H:%M:%S", localtime( &tv_req_end.tv_sec ) ); fprintf( stderr, "[%s] Slow PHP script: %d ms\n URL: %s %s\n Query String: %s\n Script: %s\n", time_buf, n, LSAPI_GetRequestMethod(), LSAPI_GetScriptName(), LSAPI_GetQueryString(), LSAPI_GetScriptFileName() ); } } LSAPI_Finish(); if ( ret ) { break; } } php_module_shutdown(); #ifdef ZTS tsrm_shutdown(); #endif return ret; }
EMBED_SAPI_API int php_embed_init(int argc, char **argv) { zend_llist global_vars; #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 sapi_startup(&php_embed_module); #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 php_embed_module.ini_entries = malloc(sizeof(HARDCODED_INI)); memcpy(php_embed_module.ini_entries, HARDCODED_INI, sizeof(HARDCODED_INI)); php_embed_module.additional_functions = additional_functions; if (argv) { php_embed_module.executable_location = argv[0]; } if (php_embed_module.startup(&php_embed_module)==FAILURE) { return FAILURE; } zend_llist_init(&global_vars, sizeof(char *), NULL, 0); /* Set some Embedded PHP defaults */ SG(options) |= SAPI_OPTION_NO_CHDIR; SG(request_info).argc=argc; SG(request_info).argv=argv; if (php_request_startup()==FAILURE) { php_module_shutdown(); return FAILURE; } SG(headers_sent) = 1; SG(request_info).no_headers = 1; php_register_variable("PHP_SELF", "-", NULL); return SUCCESS; }
/* {{{ 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(); }