PHP: added setting of individual configuration options.

This commit is contained in:
Valentin Bartenev
2018-06-07 16:17:32 +03:00
parent 388390888b
commit 8f278a5fed
2 changed files with 98 additions and 0 deletions

View File

@@ -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;
}

View File

@@ -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)