Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Optimized shutdown sequence to iterate only over modified ini directives

  • Loading branch information...
commit 14cad8fdc377e8e7373456942f2a7b617beb2fb4 1 parent b5cd968
Dmitry Stogov authored
Showing with 26 additions and 3 deletions.
  1. +2 −0  Zend/zend_globals.h
  2. +24 −3 Zend/zend_ini.c
View
2  Zend/zend_globals.h
@@ -227,6 +227,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;
View
27 Zend/zend_ini.c
@@ -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;
}
@@ -237,12 +249,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);
}
@@ -260,7 +277,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;
}
Please sign in to comment.
Something went wrong with that request. Please try again.