diff options
Diffstat (limited to '')
-rw-r--r-- | src/nxt_conf_validation.c | 30 | ||||
-rw-r--r-- | src/nxt_php_sapi.c | 68 |
2 files changed, 98 insertions, 0 deletions
diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c index 6cbd8f22..7d9c9631 100644 --- a/src/nxt_conf_validation.c +++ b/src/nxt_conf_validation.c @@ -69,6 +69,8 @@ static nxt_int_t nxt_conf_vldt_environment(nxt_conf_validation_t *vldt, nxt_str_t *name, nxt_conf_value_t *value); static nxt_int_t nxt_conf_vldt_argument(nxt_conf_validation_t *vldt, nxt_conf_value_t *value); +static nxt_int_t nxt_conf_vldt_php_option(nxt_conf_validation_t *vldt, + nxt_str_t *name, nxt_conf_value_t *value); static nxt_conf_vldt_object_t nxt_conf_vldt_root_members[] = { @@ -207,6 +209,16 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_php_options_members[] = { NULL, NULL }, + { nxt_string("admin"), + NXT_CONF_VLDT_OBJECT, + &nxt_conf_vldt_object_iterator, + (void *) &nxt_conf_vldt_php_option }, + + { nxt_string("user"), + NXT_CONF_VLDT_OBJECT, + &nxt_conf_vldt_object_iterator, + (void *) &nxt_conf_vldt_php_option }, + NXT_CONF_VLDT_END }; @@ -841,3 +853,21 @@ nxt_conf_vldt_argument(nxt_conf_validation_t *vldt, nxt_conf_value_t *value) return NXT_OK; } + + +static nxt_int_t +nxt_conf_vldt_php_option(nxt_conf_validation_t *vldt, nxt_str_t *name, + nxt_conf_value_t *value) +{ + if (name->length == 0) { + return nxt_conf_vldt_error(vldt, + "The PHP option name must not be empty."); + } + + if (nxt_conf_type(value) != NXT_CONF_STRING) { + return nxt_conf_vldt_error(vldt, "The \"%V\" PHP option must be " + "a string.", name); + } + + return NXT_OK; +} diff --git a/src/nxt_php_sapi.c b/src/nxt_php_sapi.c index f0a1d685..5aae2f45 100644 --- a/src/nxt_php_sapi.c +++ b/src/nxt_php_sapi.c @@ -35,6 +35,8 @@ static nxt_int_t nxt_php_run(nxt_task_t *task, #endif static int nxt_php_startup(sapi_module_struct *sapi_module); +static void nxt_php_set_options(nxt_task_t *task, nxt_conf_value_t *options, + int type); static int nxt_php_send_headers(sapi_headers_struct *sapi_headers); static char *nxt_php_read_cookies(void); static void nxt_php_register_variables(zval *track_vars_array); @@ -190,6 +192,8 @@ nxt_php_init(nxt_task_t *task, nxt_common_app_conf_t *conf) nxt_php_app_conf_t *c; static nxt_str_t file_str = nxt_string("file"); + static nxt_str_t user_str = nxt_string("user"); + static nxt_str_t admin_str = nxt_string("admin"); c = &conf->u.php; @@ -295,10 +299,74 @@ nxt_php_init(nxt_task_t *task, nxt_common_app_conf_t *conf) nxt_php_startup(&nxt_php_sapi_module); + if (c->options != NULL) { + value = nxt_conf_get_object_member(c->options, &admin_str, NULL); + nxt_php_set_options(task, value, ZEND_INI_SYSTEM); + + value = nxt_conf_get_object_member(c->options, &user_str, NULL); + nxt_php_set_options(task, value, ZEND_INI_USER); + } + return NXT_OK; } +static void +nxt_php_set_options(nxt_task_t *task, nxt_conf_value_t *options, int type) +{ + int ret; + uint32_t next; + nxt_str_t name, value; + nxt_conf_value_t *value_obj; +#if PHP_MAJOR_VERSION >= 7 + zend_string *zs; +#else + char buf[256]; +#endif + + if (options != NULL) { + next = 0; + + for ( ;; ) { + value_obj = nxt_conf_next_object_member(options, &name, &next); + if (value_obj == NULL) { + break; + } + + nxt_conf_get_string(value_obj, &value); + +#if PHP_MAJOR_VERSION >= 7 + /* PHP exits on memory allocation errors. */ + zs = zend_string_init((char *) name.start, name.length, 1); + + ret = zend_alter_ini_entry_chars(zs, (char *) value.start, + value.length, type, + ZEND_INI_STAGE_ACTIVATE); + + zend_string_release(zs); +#else + if (nxt_fast_path(name.length < sizeof(buf))) { + nxt_memcpy(buf, name.start, name.length); + buf[name.length] = '\0'; + + ret = zend_alter_ini_entry(buf, name.length + 1, + (char *) value.start, value.length, + type, ZEND_INI_STAGE_ACTIVATE); + + } else { + ret = FAILURE; + } +#endif + + if (ret == FAILURE) { + nxt_log(task, NXT_LOG_ERR, + "setting PHP option \"%V: %V\" failed", &name, &value); + } + } + } +} + + static nxt_int_t nxt_php_read_request(nxt_task_t *task, nxt_app_rmsg_t *rmsg, nxt_php_run_ctx_t *ctx) |