]> granicus.if.org Git - php/commitdiff
Optimized request shutdown sequence to iterate only over modified ini directives
authorDmitry Stogov <dmitry@php.net>
Mon, 15 May 2006 14:53:47 +0000 (14:53 +0000)
committerDmitry Stogov <dmitry@php.net>
Mon, 15 May 2006 14:53:47 +0000 (14:53 +0000)
Zend/zend_globals.h
Zend/zend_ini.c

index 537ea3440829360bd69915e0c9135b031cf53ad8..1c6d5c46031efbb3c4d1d68c6bd527b18673dc98 100644 (file)
@@ -220,6 +220,8 @@ struct _zend_executor_globals {
        int lambda_count;
 
        HashTable *ini_directives;
+       HashTable *modified_ini_directives;
+
        zend_objects_store objects_store;
        zval *exception;
        zend_op *opline_before_exception;
index 148251b1a2fd6166b5277cbb86936c41fe6ec82b..0d144bea8babee891112d2caf4fd464acd0448f9 100644 (file)
@@ -65,6 +65,12 @@ static int zend_restore_ini_entry_cb(zend_ini_entry *ini_entry, int stage TSRMLS
        return 0;
 }
 
+static int zend_restore_ini_entry_wrapper(zend_ini_entry **ini_entry TSRMLS_DC)
+{
+       zend_restore_ini_entry_cb(*ini_entry, ZEND_INI_STAGE_DEACTIVATE TSRMLS_CC);
+       return 1;
+}
+
 /*
  * Startup / shutdown
  */
@@ -73,6 +79,7 @@ ZEND_API int zend_ini_startup(TSRMLS_D)
        registered_zend_ini_directives = (HashTable *) malloc(sizeof(HashTable));
 
        EG(ini_directives) = registered_zend_ini_directives;
+       EG(modified_ini_directives) = NULL;
        if (zend_hash_init_ex(registered_zend_ini_directives, 100, NULL, NULL, 1, 0)==FAILURE) {
                return FAILURE;
        }
@@ -98,7 +105,12 @@ ZEND_API int zend_ini_global_shutdown(TSRMLS_D)
 
 ZEND_API int zend_ini_deactivate(TSRMLS_D)
 {
-       zend_hash_apply_with_argument(EG(ini_directives), (apply_func_arg_t) zend_restore_ini_entry_cb, (void *) ZEND_INI_STAGE_DEACTIVATE TSRMLS_CC);
+       if (EG(modified_ini_directives)) {
+               zend_hash_apply(EG(modified_ini_directives), (apply_func_t) zend_restore_ini_entry_wrapper TSRMLS_CC);
+               zend_hash_destroy(EG(modified_ini_directives));
+               FREE_HASHTABLE(EG(modified_ini_directives));
+               EG(modified_ini_directives) = NULL;
+       }
        return SUCCESS;
 }
 
@@ -238,12 +250,17 @@ ZEND_API int zend_alter_ini_entry(char *name, uint name_length, char *new_value,
                if (!ini_entry->modified) {
                        ini_entry->orig_value = ini_entry->value;
                        ini_entry->orig_value_length = ini_entry->value_length;
+                       ini_entry->modified = 1;
+                       if (!EG(modified_ini_directives)) {
+                               ALLOC_HASHTABLE(EG(modified_ini_directives));
+                               zend_hash_init(EG(modified_ini_directives), 8, NULL, NULL, 0);
+                       }
+                       zend_hash_add(EG(modified_ini_directives), name, name_length, &ini_entry, sizeof(zend_ini_entry*), NULL);
                } else { /* we already changed the value, free the changed value */
                        efree(ini_entry->value);
                }
                ini_entry->value = duplicate;
                ini_entry->value_length = new_value_length;
-               ini_entry->modified = 1;
        } else {
                efree(duplicate);
        }
@@ -261,7 +278,11 @@ ZEND_API int zend_restore_ini_entry(char *name, uint name_length, int stage)
                return FAILURE;
        }
 
-       zend_restore_ini_entry_cb(ini_entry, stage TSRMLS_CC);
+       if (EG(modified_ini_directives)) {
+               zend_restore_ini_entry_cb(ini_entry, stage TSRMLS_CC);
+               zend_hash_del(EG(modified_ini_directives), name, name_length);
+       }
+       
        return SUCCESS;
 }