]> granicus.if.org Git - php/commitdiff
Implemented -n switch to skip parsing ini at startup as suggested by Wez.
authorMarcus Boerger <helly@php.net>
Tue, 12 Nov 2002 20:56:47 +0000 (20:56 +0000)
committerMarcus Boerger <helly@php.net>
Tue, 12 Nov 2002 20:56:47 +0000 (20:56 +0000)
#The switch 'n' was planned to be used for beautifying....delete n to make
#clear these functions do not have a switch yet.

main/SAPI.h
main/php_ini.c
sapi/cgi/cgi_main.c
sapi/cli/php_cli.c

index b720e41ea82c0c222ff83dc863ea246ad7a0a63f..7e0464ffeaff3e35df6bda4111a8ee722b3eab39 100644 (file)
@@ -218,6 +218,8 @@ struct _sapi_module_struct {
        void (*default_post_reader)(TSRMLS_D);
        void (*treat_data)(int arg, char *str, zval *destArray TSRMLS_DC);
        char *executable_location;
+
+       int php_ini_ignore;
 };
 
 
@@ -251,7 +253,7 @@ SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data);
 SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader);
 SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data);
 
-#define STANDARD_SAPI_MODULE_PROPERTIES NULL, NULL
+#define STANDARD_SAPI_MODULE_PROPERTIES NULL, NULL, 0
 
 #endif /* SAPI_H */
 
index e439547809b5e6c5603f6f40e9828166d10aed12..af41b6c97b194b08971a6615c040c1622cbe784a 100644 (file)
@@ -340,32 +340,34 @@ int php_init_config()
 
        fh.handle.fp = NULL;
        /* Check if php_ini_path_override is a file */
-       if (sapi_module.php_ini_path_override && sapi_module.php_ini_path_override[0]) {
-               struct stat statbuf;
-
-               if (!VCWD_STAT(sapi_module.php_ini_path_override, &statbuf)) {
-                       if (!((statbuf.st_mode & S_IFMT) == S_IFDIR)) {
-                               fh.handle.fp = VCWD_FOPEN(sapi_module.php_ini_path_override, "r");
-                               fh.filename = sapi_module.php_ini_path_override;
+       if (!sapi_module.php_ini_ignore) {
+               if (sapi_module.php_ini_path_override && sapi_module.php_ini_path_override[0]) {
+                       struct stat statbuf;
+       
+                       if (!VCWD_STAT(sapi_module.php_ini_path_override, &statbuf)) {
+                               if (!((statbuf.st_mode & S_IFMT) == S_IFDIR)) {
+                                       fh.handle.fp = VCWD_FOPEN(sapi_module.php_ini_path_override, "r");
+                                       fh.filename = sapi_module.php_ini_path_override;
+                               }
                        }
                }
-       }
-       /* Search php-%sapi-module-name%.ini file in search path */
-       if (!fh.handle.fp) {
-               const char *fmt = "php-%s.ini";
-               char *ini_fname=emalloc(strlen(fmt)+strlen(sapi_module.name));
-               sprintf(ini_fname, fmt, sapi_module.name);
-               fh.handle.fp = php_fopen_with_path(ini_fname, "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC);
-               efree(ini_fname);
-               if (fh.handle.fp) {
-                       fh.filename = php_ini_opened_path;
+               /* Search php-%sapi-module-name%.ini file in search path */
+               if (!fh.handle.fp) {
+                       const char *fmt = "php-%s.ini";
+                       char *ini_fname=emalloc(strlen(fmt)+strlen(sapi_module.name));
+                       sprintf(ini_fname, fmt, sapi_module.name);
+                       fh.handle.fp = php_fopen_with_path(ini_fname, "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC);
+                       efree(ini_fname);
+                       if (fh.handle.fp) {
+                               fh.filename = php_ini_opened_path;
+                       }
                }
-       }
-       /* Search php.ini file in search path */
-       if (!fh.handle.fp) {
-               fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC);
-               if (fh.handle.fp) {
-                       fh.filename = php_ini_opened_path;
+               /* Search php.ini file in search path */
+               if (!fh.handle.fp) {
+                       fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC);
+                       if (fh.handle.fp) {
+                               fh.filename = php_ini_opened_path;
+                       }
                }
        }
        if (free_ini_search_path) {
@@ -390,7 +392,7 @@ int php_init_config()
                                efree(php_ini_opened_path);
                        php_ini_opened_path = zend_strndup(Z_STRVAL(tmp), Z_STRLEN(tmp));
                }
-       }       
+       }
 
        /* If the config_file_scan_dir is set at compile-time, go and scan this directory and
         * parse any .ini files found in this directory. */
index bd8e46bddf1f4a2a28ff66515b7b34dda510f19a..068205a9c408d86eac91305c694ef1797c5cbf7d 100644 (file)
@@ -406,6 +406,7 @@ static void php_cgi_usage(char *argv0)
 #endif
                           "  -C               Do not chdir to the script's directory\n"
                           "  -c <path>|<file> Look for php.ini file in this directory\n"
+                          "  -n               No php.ini file will be used\n"
                           "  -d foo[=bar]     Define INI entry foo with value 'bar'\n"
                           "  -e               Generate extended information for debugger/profiler\n"
                           "  -f <file>        Parse <file>.  Implies `-q'\n"
@@ -617,6 +618,9 @@ int main(int argc, char *argv[])
                                case 'c':
                                        cgi_sapi_module.php_ini_path_override = strdup(ap_php_optarg);
                                        break;
+                               case 'n':
+                                       cgi_sapi_module.php_ini_ignore = 1;
+                                       break;
                        }
 
                }
@@ -884,6 +888,17 @@ consult the installation file that came with this distribution, or visit \n\
                                free(SG(request_info).argv0);
                                SG(request_info).argv0 = NULL;
                        }
+
+                       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 = ap_php_getopt(argc, argv, OPTSTRING)) != -1) {
                                switch (c) {
                                        
@@ -960,7 +975,7 @@ consult the installation file that came with this distribution, or visit \n\
                                        break;
 
 #if 0 /* not yet operational, see also below ... */
-                               case 'n': /* generate indented source mode*/ 
+                               case '': /* generate indented source mode*/ 
                                                behavior=PHP_MODE_INDENT;
                                                break;
 #endif
index c986ee3dc793749aa3612f890657b05c7b455a8b..a34ca225dcaea9381e07e3e458fddab4219d764f 100644 (file)
@@ -264,6 +264,7 @@ static void php_cli_usage(char *argv0)
                    "       %s [options] [-- args...]\n"
                                "  -a               Run interactively\n"
                                "  -c <path>|<file> Look for php.ini file in this directory\n"
+                               "  -n               No php.ini file will be used\n"
                                "  -d foo[=bar]     Define INI entry foo with value 'bar'\n"
                                "  -e               Generate extended information for debugger/profiler\n"
                                "  -f <file>        Parse <file>.\n"
@@ -423,8 +424,10 @@ int main(int argc, char *argv[])
                case 'c':
                        cli_sapi_module.php_ini_path_override = strdup(ap_php_optarg);
                        break;
+               case 'n':
+                       cli_sapi_module.php_ini_ignore = 1;
+                       break;
                }
-
        }
        ap_php_optind = orig_optind;
        ap_php_optarg = orig_optarg;
@@ -479,6 +482,13 @@ int main(int argc, char *argv[])
 
                zend_uv.html_errors = 0; /* tell the engine we're in non-html mode */
 
+               if (cli_sapi_module.php_ini_path_override && cli_sapi_module.php_ini_ignore) {
+                       SG(headers_sent) = 1;
+                       SG(request_info).no_headers = 1;
+                       PUTS("You cannot use both -n and -c switch. Use -h for help.\n");
+                       exit(1);
+               }
+       
                while ((c = ap_php_getopt(argc, argv, OPTSTRING)) != -1) {
                        switch (c) {
 
@@ -561,7 +571,7 @@ int main(int argc, char *argv[])
                        break;
 
 #if 0 /* not yet operational, see also below ... */
-                       case 'n': /* generate indented source mode*/
+                       case '': /* generate indented source mode*/
                                if (behavior == PHP_MODE_CLI_DIRECT) {
                                        param_error = "Source indenting only works for files.\n";
                                        break;