]> granicus.if.org Git - php/commitdiff
- A few fixes
authorZeev Suraski <zeev@php.net>
Fri, 28 Jan 2000 18:29:37 +0000 (18:29 +0000)
committerZeev Suraski <zeev@php.net>
Fri, 28 Jan 2000 18:29:37 +0000 (18:29 +0000)
- Added register_argv_argc directive to allow disabling of argv/argc

NEWS
ext/session/session.c
main/main.c
main/php_globals.h
main/php_variables.c
php.ini-dist
sapi/cgi/cgi_main.c

diff --git a/NEWS b/NEWS
index 7c54d8f37c0cd8ec1de7cd8c668db5d9e129aa4d..26c07b9d68d1715a44bc56130730bb642d9602a5 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,11 +2,14 @@ PHP 4.0                                                                    NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 
 ?? ?? ????, Version 4.0 Beta 4
+- Added register_argc_argv INI directive, to allow to selectively disable
+  the declaration of the $argv and $argc variables for increased
+  performance (Zeev)
 - Added $HTTP_ENV_VARS[] and $HTTP_SERVER_VARS[] support, which similarly
   to $HTTP_GET_VARS[], contain environment and server variables.  Setting
   register_globals to Off will now also prevent registration of the
   environment and server variables into the global scope (Zeev)
-- Renamed gpc_globals to register_globals (Zeev)
+- Renamed gpc_globals INI directive to register_globals (Zeev)
 - Introduced variables_order that deprecates gpc_order, and allows control
   over the server and environment variables, in addition to GET/POST/Cookies
   (Zeev)
index a4e99225cafd5d99dac0a7bb73e859e69f2c8c2e..ed359e973792af777e66c69f3fe9c70e7a43157b 100644 (file)
@@ -181,10 +181,10 @@ static void php_set_session_var(char *name, size_t namelen,
        zval_copy_ctor(state_val_copy);
        state_val_copy->refcount = 0;
 
-       if (PG(gpc_globals) && PG(track_vars)) {
+       if (PG(register_globals) && PG(track_vars)) {
                zend_set_hash_symbol(state_val_copy, name, namelen, 1, 2, PS(http_state_vars)->value.ht, &EG(symbol_table));
        } else {
-               if (PG(gpc_globals)) {
+               if (PG(register_globals)) {
                        zend_set_hash_symbol(state_val_copy, name, namelen, 0, 1, &EG(symbol_table));
                }
 
@@ -639,7 +639,7 @@ static void _php_session_start(PSLS_D)
        char *p;
        int send_cookie = 1;
        int define_sid = 1;
-       zend_bool gpc_globals;
+       zend_bool register_globals;
        zend_bool track_vars;
        int module_number = PS(module_number);
        int nrand;
@@ -650,11 +650,11 @@ static void _php_session_start(PSLS_D)
 
        lensess = strlen(PS(session_name));
        
-       gpc_globals = INI_BOOL("gpc_globals");
+       register_globals = INI_BOOL("register_globals");
        track_vars = INI_BOOL("track_vars");
 
-       if (!gpc_globals && !track_vars) {
-               php_error(E_ERROR, "The sessions module will not work, if you have disabled track_vars and gpc_globals. Enable at least one of them.");
+       if (!register_globals && !track_vars) {
+               php_error(E_ERROR, "The sessions module will not work, if you have disabled track_vars and register_globals. Enable at least one of them.");
                return;
        }
 
@@ -669,7 +669,7 @@ static void _php_session_start(PSLS_D)
         * cookie.
         */
        
-       if (gpc_globals && 
+       if (register_globals && 
                        !track_vars &&
                        !PS(id) &&
                        zend_hash_find(&EG(symbol_table), PS(session_name),
index 2c1789c38514f08e4a6a1e23ae69f5922b739479..5fb79f0702f79db749484781c234263f62e45be7 100644 (file)
@@ -97,7 +97,7 @@ static MUTEX_T global_lock;
 #endif
  
 
-void _php_build_argv(char * ELS_DC);
+static void php_build_argv(char *s, zval *track_vars_array ELS_DC PLS_DC);
 static void php_timeout(int dummy);
 static void php_set_timeout(long seconds);
 
@@ -250,7 +250,8 @@ PHP_INI_BEGIN()
        STD_PHP_INI_BOOLEAN("track_vars",                       "0",                    PHP_INI_ALL,            OnUpdateBool,                           track_vars,             php_core_globals,       core_globals)
 #endif
 
-       STD_PHP_INI_BOOLEAN("register_globals",                 "1",                    PHP_INI_ALL,            OnUpdateBool,                           gpc_globals,    php_core_globals,       core_globals)
+       STD_PHP_INI_BOOLEAN("register_globals",         "1",                    PHP_INI_ALL,            OnUpdateBool,                   register_globals,       php_core_globals,       core_globals)
+       STD_PHP_INI_BOOLEAN("register_argc_argv",       "1",                    PHP_INI_ALL,            OnUpdateBool,                   register_argc_argv,     php_core_globals,       core_globals)
        STD_PHP_INI_ENTRY("gpc_order",                          "GPC",                  PHP_INI_ALL,            OnUpdateStringUnempty,  gpc_order,                      php_core_globals,       core_globals)
        STD_PHP_INI_ENTRY("variables_order",            NULL,                   PHP_INI_ALL,            OnUpdateStringUnempty,  variables_order,        php_core_globals,       core_globals)
        STD_PHP_INI_ENTRY("arg_separator",                      "&",                    PHP_INI_ALL,            OnUpdateStringUnempty,  arg_separator,          php_core_globals,       core_globals)
@@ -1007,6 +1008,10 @@ static inline void php_register_server_variables(ELS_D SLS_DC PLS_DC)
                zend_hash_add(&EG(symbol_table), "HTTP_SERVER_VARS", sizeof("HTTP_SERVER_VARS"), &array_ptr, sizeof(pval *),NULL);
        }
        sapi_module.register_server_variables(array_ptr ELS_CC SLS_CC PLS_CC);
+
+       if (PG(register_argc_argv)) {
+               php_build_argv(SG(request_info).query_string, array_ptr ELS_CC PLS_CC);
+       }
 }
 
 
@@ -1070,30 +1075,21 @@ static int php_hash_environment(ELS_D SLS_DC PLS_DC)
                php_register_server_variables(ELS_C SLS_CC PLS_CC);
        }
 
-
-       /* need argc/argv support as well */
-       _php_build_argv(SG(request_info).query_string ELS_CC);
-
        return SUCCESS;
 }
 
 
-void _php_build_argv(char *s ELS_DC)
+static void php_build_argv(char *s, zval *track_vars_array ELS_DC PLS_DC)
 {
-       pval *arr, *tmp;
+       pval *arr, *argc, *tmp;
        int count = 0;
        char *ss, *space;
 
        ALLOC_ZVAL(arr);
-       arr->value.ht = (HashTable *) emalloc(sizeof(HashTable));
-       if (zend_hash_init(arr->value.ht, 0, NULL, ZVAL_PTR_DTOR, 0) == FAILURE) {
-               php_error(E_WARNING, "Unable to create argv array");
-       } else {
-               arr->type = IS_ARRAY;
-               INIT_PZVAL(arr);
-               zend_hash_update(&EG(symbol_table), "argv", sizeof("argv"), &arr, sizeof(pval *), NULL);
-       }
-       /* now pick out individual entries */
+       array_init(arr);
+       INIT_PZVAL(arr);
+
+       /* Prepare argv */
        ss = s;
        while (ss) {
                space = strchr(ss, '+');
@@ -1119,11 +1115,27 @@ void _php_build_argv(char *s ELS_DC)
                        ss = space;
                }
        }
-       ALLOC_ZVAL(tmp);
-       tmp->value.lval = count;
-       tmp->type = IS_LONG;
-       INIT_PZVAL(tmp);
-       zend_hash_add(&EG(symbol_table), "argc", sizeof("argc"), &tmp, sizeof(pval *), NULL);
+
+       /* prepare argc */
+       ALLOC_ZVAL(argc);
+       argc->value.lval = count;
+       argc->type = IS_LONG;
+       INIT_PZVAL(argc);
+
+       if (PG(register_globals)) {
+               zend_hash_update(&EG(symbol_table), "argv", sizeof("argv"), &arr, sizeof(pval *), NULL);
+               zend_hash_add(&EG(symbol_table), "argc", sizeof("argc"), &argc, sizeof(pval *), NULL);
+       }
+
+       if (PG(track_vars)) {
+               if (!PG(register_globals)) {
+                       arr->refcount++;
+                       argc->refcount++;
+               }
+               zend_hash_update(&EG(symbol_table), "argv", sizeof("argv"), &arr, sizeof(pval *), NULL);
+               zend_hash_add(&EG(symbol_table), "argc", sizeof("argc"), &argc, sizeof(pval *), NULL);
+       }
+
 }
 
 
index 8bb5792c825dfee6fb27caab2a845e79997d2fa7..b6e086ced34ea4a0d9aafd1277a7e061d2a66752 100644 (file)
@@ -86,7 +86,8 @@ struct _php_core_globals {
        zend_bool expose_php;
 
        zend_bool track_vars;
-       zend_bool gpc_globals;
+       zend_bool register_globals;
+       zend_bool register_argc_argv;
 
        zend_bool y2k_compliance;
 
index b4355b4ee8560bf22de7c9c077f46aafffdc2231..383442ab66ea2f4e442c9d676f5cbc26cdcd74b5 100644 (file)
@@ -40,7 +40,7 @@ PHPAPI void php_register_variable(char *val, char *var, pval *track_vars_array E
        HashTable *symtable1=NULL;
        HashTable *symtable2=NULL;
        
-       if (PG(gpc_globals)) {
+       if (PG(register_globals)) {
                symtable1 = EG(active_symbol_table);
        }
        if (track_vars_array) {
index 4714a1bb917ad8d79320b39f34160ef77fd7eeac..583f5df0bde32e3cb913d9660a153a4f242ce3e9 100644 (file)
@@ -146,6 +146,10 @@ register_globals   =       On              ; Whether or not to register the EGPCB variables as globa
                                                                ; most sense when coupled with track_vars - in which case you can
                                                                ; access all of the GPC variables through the $HTTP_*_VARS[],
                                                                ; variables.
+register_argv_argc     =       On              ; This directive tells PHP whether to declare the argv&argc
+                                                               ; variables (that would contain the GET information).  If you
+                                                               ; don't use these variables, you should turn it off for
+                                                               ; increased performance
 track_vars                     =       On              ; enable the $HTTP_*_VARS[] arrays, where * is one of
                                                                ; ENV, POST, GET, COOKIE or SERVER.
 gpc_order                      =       "GPC"   ; This directive is deprecated.  Use variables_order instead.
index 4ed0442c43fadbd82bd33ff2b1e8db810f60cdbf..2f3587808686b67b4043b0704b3ead2c6ee82488 100644 (file)
@@ -153,6 +153,7 @@ static void sapi_cgi_register_variables(zval *track_vars_array ELS_DC SLS_DC PLS
                val = emalloc(l + 1);
                php_sprintf(val, "%s%s", (sn ? sn : ""), (pi ? pi : ""));       /* SAFE */
                php_register_variable(val, "PHP_SELF", track_vars_array ELS_CC PLS_CC);
+               efree(val);
        }
 #endif
 }