📄 cgi_main.c
字号:
exit(1); break; } } php_optind = orig_optind; php_optarg = orig_optarg; }#if PHP_FASTCGI /* start of FAST CGI loop */ /* Initialise FastCGI request structure */#ifdef PHP_WIN32 /* attempt to set security impersonation for fastcgi will only happen on NT based OS, others will ignore it. */ if (fastcgi) { if (cfg_get_long("fastcgi.impersonate", &impersonate) == FAILURE) { impersonate = 0; } if (impersonate) OS_SetImpersonate(); }#endif while (!fastcgi || FCGX_Accept_r( &request ) >= 0) {#endif#if PHP_FASTCGI SG(server_context) = (void *) &request;#else SG(server_context) = (void *) 1; /* avoid server_context==NULL checks */#endif init_request_info(TSRMLS_C); zend_llist_init(&global_vars, sizeof(char *), NULL, 0); CG(interactive) = 0; if (!cgi#if PHP_FASTCGI && !fastcgi#endif ) { if (cgi_sapi_module.php_ini_path_override && cgi_sapi_module.php_ini_ignore) { no_headers = 1; php_output_startup(); php_output_activate(TSRMLS_C); SG(headers_sent) = 1; php_printf("You cannot use both -n and -c switch. Use -h for help.\n"); php_end_ob_buffers(1 TSRMLS_CC); exit(1); } while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0)) != -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 */ SG(options) |= SAPI_OPTION_NO_CHDIR; break; case 'd': /* define ini entries on command line */ define_command_line_ini_entry(php_optarg); break; case 'e': /* enable extended info output */ CG(extended_info) = 1; break; case 'f': /* parse file */ script_file = estrdup(php_optarg); no_headers = 1; /* arguments after the file are considered script args */ SG(request_info).argc = argc - (php_optind-1); SG(request_info).argv = &argv[php_optind-1]; break; case 'g': /* define global variables on command line */ { char *arg = estrdup(php_optarg); zend_llist_add_element(&global_vars, &arg); } break; case 'i': /* php info & quit */ if (php_request_startup(TSRMLS_C) == FAILURE) { php_module_shutdown(TSRMLS_C); return FAILURE; } if (no_headers) { SG(headers_sent) = 1; SG(request_info).no_headers = 1; } php_print_info(0xFFFFFFFF TSRMLS_CC); php_end_ob_buffers(1 TSRMLS_CC); exit(0); break; case 'l': /* syntax check mode */ no_headers = 1; behavior=PHP_MODE_LINT; break; case 'm': /* list compiled in modules */ php_output_startup(); php_output_activate(TSRMLS_C); SG(headers_sent) = 1; php_printf("[PHP Modules]\n"); print_modules(TSRMLS_C); php_printf("\n[Zend Modules]\n"); print_extensions(TSRMLS_C); php_printf("\n"); php_end_ob_buffers(1 TSRMLS_CC); exit(0); break;#if 0 /* not yet operational, see also below ... */ case '': /* generate indented source mode*/ behavior=PHP_MODE_INDENT; break;#endif case 'q': /* do not generate HTTP headers */ no_headers = 1; break; case 's': /* generate highlighted HTML from source */ behavior=PHP_MODE_HIGHLIGHT; break; case 'v': /* show php version & quit */ no_headers = 1; if (php_request_startup(TSRMLS_C) == FAILURE) { php_module_shutdown(TSRMLS_C); return FAILURE; } if (no_headers) { SG(headers_sent) = 1; SG(request_info).no_headers = 1; }#if ZEND_DEBUG php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) 1997-2007 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-2007 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());#endif php_end_ob_buffers(1 TSRMLS_CC); exit(0); break; case 'w': behavior=PHP_MODE_STRIP; break; case 'z': /* load extension file */ zend_load_extension(php_optarg); break; default: break; } } if (script_file) { /* override path_translated if -f on command line */ if (SG(request_info).path_translated) { STR_FREE(SG(request_info).path_translated); } SG(request_info).path_translated = script_file; } if (no_headers) { SG(headers_sent) = 1; SG(request_info).no_headers = 1; } if (!SG(request_info).path_translated && argc > php_optind) { /* arguments after the file are considered script args */ SG(request_info).argc = argc - php_optind; SG(request_info).argv = &argv[php_optind]; /* file is on command line, but not in -f opt */ SG(request_info).path_translated = estrdup(argv[php_optind++]); } /* all remaining arguments are part of the query string this section of code concatenates all remaining arguments into a single string, seperating args with a & this allows command lines like: test.php v1=test v2=hello+world! test.php "v1=test&v2=hello world!" test.php v1=test "v2=hello world!" */ if (!SG(request_info).query_string && argc > php_optind) { len = 0; for (i = php_optind; i < argc; i++) { len += strlen(argv[i]) + 1; } s = malloc(len + 1); /* leak - but only for command line version, so ok */ *s = '\0'; /* we are pretending it came from the environment */ for (i = php_optind, len = 0; i < argc; i++) { strcat(s, argv[i]); if (i < (argc - 1)) { strcat(s, PG(arg_separator).input); } } SG(request_info).query_string = s; } } /* end !cgi && !fastcgi */ /* we never take stdin if we're (f)cgi, always rely on the web server giving us the info we need in the environment. */ if (SG(request_info).path_translated || cgi #if PHP_FASTCGI || fastcgi#endif ) { file_handle.type = ZEND_HANDLE_FILENAME; file_handle.filename = SG(request_info).path_translated; file_handle.handle.fp = NULL; } else { file_handle.filename = "-"; file_handle.type = ZEND_HANDLE_FP; file_handle.handle.fp = stdin; } file_handle.opened_path = NULL; file_handle.free_filename = 0; /* request startup only after we've done all we can to get path_translated */ if (php_request_startup(TSRMLS_C)==FAILURE) {#if PHP_FASTCGI if (fastcgi) { FCGX_Finish_r(&request); }#endif php_module_shutdown(TSRMLS_C); return FAILURE; } if (no_headers) { SG(headers_sent) = 1; SG(request_info).no_headers = 1; } /* This actually destructs the elements of the list - ugly hack */ zend_llist_apply(&global_vars, (llist_apply_func_t) php_register_command_line_global_vars TSRMLS_CC); zend_llist_destroy(&global_vars); /* at this point path_translated will be set if: 1. we are running from shell and got filename was there 2. we are running as cgi or fastcgi */ if (cgi || SG(request_info).path_translated) { retval = php_fopen_primary_script(&file_handle TSRMLS_CC); } /* if we are unable to open path_translated and we are not running from shell (so fp == NULL), then fail. */ if (retval == FAILURE && file_handle.handle.fp == NULL) { SG(sapi_headers).http_response_code = 404; PUTS("No input file specified.\n");#if PHP_FASTCGI /* we want to serve more requests if this is fastcgi so cleanup and continue, request shutdown is handled later */ if (fastcgi) { goto fastcgi_request_done; }#endif php_request_shutdown((void *) 0); php_module_shutdown(TSRMLS_C); return FAILURE; } if (file_handle.handle.fp && (file_handle.handle.fp != stdin)) { /* #!php support */ c = fgetc(file_handle.handle.fp); if (c == '#') { while (c != 10 && c != 13) { c = fgetc(file_handle.handle.fp); /* skip to end of line */ } /* handle situations where line is terminated by \r\n */ if (c == 13) { if (fgetc(file_handle.handle.fp) != 10) { long pos = ftell(file_handle.handle.fp); fseek(file_handle.handle.fp, pos - 1, SEEK_SET); } } CG(zend_lineno) = -2; } else { rewind(file_handle.handle.fp); } } switch (behavior) { case PHP_MODE_STANDARD: php_execute_script(&file_handle TSRMLS_CC); break; case PHP_MODE_LINT: PG(during_request_startup) = 0; exit_status = php_lint_script(&file_handle TSRMLS_CC); if (exit_status == SUCCESS) { zend_printf("No syntax errors detected in %s\n", file_handle.filename); } else { zend_printf("Errors parsing %s\n", file_handle.filename); } break; case PHP_MODE_STRIP: if (open_file_for_scanning(&file_handle TSRMLS_CC) == SUCCESS) { zend_strip(TSRMLS_C); fclose(file_handle.handle.fp); php_end_ob_buffers(1 TSRMLS_CC); } return SUCCESS; break; case PHP_MODE_HIGHLIGHT: { zend_syntax_highlighter_ini syntax_highlighter_ini; if (open_file_for_scanning(&file_handle TSRMLS_CC) == SUCCESS) { php_get_highlight_struct(&syntax_highlighter_ini); zend_highlight(&syntax_highlighter_ini TSRMLS_CC); fclose(file_handle.handle.fp); php_end_ob_buffers(1 TSRMLS_CC); } return SUCCESS; } break;#if 0 /* Zeev might want to do something with this one day */ case PHP_MODE_INDENT: open_file_for_scanning(&file_handle TSRMLS_CC); zend_indent(); fclose(file_handle.handle.fp); return SUCCESS; break;#endif }#if PHP_FASTCGIfastcgi_request_done:#endif { char *path_translated; /* Go through this trouble so that the memory manager doesn't warn * about SG(request_info).path_translated leaking */ if (SG(request_info).path_translated) { path_translated = strdup(SG(request_info).path_translated); STR_FREE(SG(request_info).path_translated); SG(request_info).path_translated = path_translated; } php_request_shutdown((void *) 0); if (exit_status == 0) { exit_status = EG(exit_status); } if (SG(request_info).path_translated) { free(SG(request_info).path_translated); SG(request_info).path_translated = NULL; } }#if PHP_FASTCGI if (!fastcgi) break; /* only fastcgi will get here */ requests++; if(max_requests && (requests == max_requests)) { FCGX_Finish_r(&request);#ifndef PHP_WIN32 if (bindpath) { free(bindpath); }#endif break; } /* end of fastcgi loop */ }#endif if (cgi_sapi_module.php_ini_path_override) { free(cgi_sapi_module.php_ini_path_override); } } zend_catch { exit_status = 255; } zend_end_try(); SG(server_context) = NULL; php_module_shutdown(TSRMLS_C);#ifdef ZTS tsrm_shutdown();#endif#if PHP_WIN32 && ZEND_DEBUG && 0 _CrtDumpMemoryLeaks( );#endif return exit_status;}/* }}} *//* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: sw=4 ts=4 fdm=marker * vim<600: sw=4 ts=4 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -