fat                                      Tue, 20 Apr 2010 21:13:40 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=298236

Log:
Change php_defines in configuration file to 
php_value,php_admin_value,php_flag,php_admin_flag (as in the apache sapi).
php_admin* sets values as ZEND_INI_SYSTEM mode while php_* sets values as 
ZEND_INI_USER

Changed paths:
    U   php/php-src/trunk/sapi/fpm/fpm/fpm_conf.c
    U   php/php-src/trunk/sapi/fpm/fpm/fpm_conf.h
    U   php/php-src/trunk/sapi/fpm/fpm/fpm_php.c
    U   php/php-src/trunk/sapi/fpm/fpm/fpm_php.h
    U   php/php-src/trunk/sapi/fpm/php-fpm.conf.in

Modified: php/php-src/trunk/sapi/fpm/fpm/fpm_conf.c
===================================================================
--- php/php-src/trunk/sapi/fpm/fpm/fpm_conf.c	2010-04-20 20:02:32 UTC (rev 298235)
+++ php/php-src/trunk/sapi/fpm/fpm/fpm_conf.c	2010-04-20 21:13:40 UTC (rev 298236)
@@ -239,12 +239,27 @@
 		return "xml_conf_set_slot_key_value_pair(): strdup() failed";
 	}

+	kv->next = **parent;
 	**parent = kv;
-	*parent = &kv->next;
 	return NULL;
 }
 /* }}} */

+static char *xml_conf_set_slot_key_value_pair_bool(void **conf, char *name, void *vv, intptr_t offset) /* {{{ */
+{
+	int value;
+	void *subconf = &value;
+	char *error;
+
+	error = xml_conf_set_slot_boolean(&subconf, name, vv, 0);
+	if (error) {
+		return error;
+	}
+
+	return(xml_conf_set_slot_key_value_pair(conf, name, value ? "On" : "Off", offset));
+}
+/* }}} */
+
 static struct xml_conf_section fpm_conf_set_key_value_pairs_subsection_conf = {
 	.path = "key_value_pairs somewhere", /* fixme */
 	.parsers = (struct xml_value_parser []) {
@@ -253,6 +268,14 @@
 	}
 };

+static struct xml_conf_section fpm_conf_set_key_value_pairs_subsection_conf_bool = {
+	.path = "key_value_pairs somewhere", /* fixme */
+	.parsers = (struct xml_value_parser []) {
+		{ XML_CONF_SCALAR, 0, &xml_conf_set_slot_key_value_pair_bool, 0 },
+		{ 0, 0, 0, 0 }
+	}
+};
+
 static char *fpm_conf_set_key_value_pairs_subsection(void **conf, char *name, void *xml_node, intptr_t offset) /* {{{ */
 {
 	void *next_kv = (char *) *conf + offset;
@@ -260,6 +283,13 @@
 }
 /* }}} */

+static char *fpm_conf_set_key_value_pairs_subsection_bool(void **conf, char *name, void *xml_node, intptr_t offset) /* {{{ */
+{
+	void *next_kv = (char *) *conf + offset;
+	return xml_conf_parse_section(&next_kv, &fpm_conf_set_key_value_pairs_subsection_conf_bool, xml_node);
+}
+/* }}} */
+
 static void *fpm_worker_pool_config_alloc() /* {{{ */
 {
 	static struct fpm_worker_pool_s *current_wp = 0;
@@ -303,12 +333,18 @@
 		free(wpc->listen_options->mode);
 		free(wpc->listen_options);
 	}
-	for (kv = wpc->php_defines; kv; kv = kv_next) {
+	for (kv = wpc->php_values; kv; kv = kv_next) {
 		kv_next = kv->next;
 		free(kv->key);
 		free(kv->value);
 		free(kv);
 	}
+	for (kv = wpc->php_admin_values; kv; kv = kv_next) {
+		kv_next = kv->next;
+		free(kv->key);
+		free(kv->value);
+		free(kv);
+	}
 	for (kv = wpc->environment; kv; kv = kv_next) {
 		kv_next = kv->next;
 		free(kv->key);
@@ -334,7 +370,10 @@
 		{ XML_CONF_SCALAR,		"name",							&xml_conf_set_slot_string,					offsetof(struct fpm_worker_pool_config_s, name) },
 		{ XML_CONF_SCALAR,		"listen_address",				&xml_conf_set_slot_string,					offsetof(struct fpm_worker_pool_config_s, listen_address) },
 		{ XML_CONF_SUBSECTION,	"listen_options",				&fpm_conf_set_listen_options_subsection,	offsetof(struct fpm_worker_pool_config_s, listen_options) },
-		{ XML_CONF_SUBSECTION,	"php_defines",					&fpm_conf_set_key_value_pairs_subsection,	offsetof(struct fpm_worker_pool_config_s, php_defines) },
+		{ XML_CONF_SUBSECTION,	"php_value",					&fpm_conf_set_key_value_pairs_subsection,	offsetof(struct fpm_worker_pool_config_s, php_values) },
+		{ XML_CONF_SUBSECTION,	"php_flag",					&fpm_conf_set_key_value_pairs_subsection_bool,	offsetof(struct fpm_worker_pool_config_s, php_values) },
+		{ XML_CONF_SUBSECTION,	"php_admin_value",					&fpm_conf_set_key_value_pairs_subsection,	offsetof(struct fpm_worker_pool_config_s, php_admin_values) },
+		{ XML_CONF_SUBSECTION,	"php_admin_flag",					&fpm_conf_set_key_value_pairs_subsection_bool,	offsetof(struct fpm_worker_pool_config_s, php_admin_values) },
 		{ XML_CONF_SCALAR,		"user",							&xml_conf_set_slot_string,					offsetof(struct fpm_worker_pool_config_s, user) },
 		{ XML_CONF_SCALAR,		"group",						&xml_conf_set_slot_string,					offsetof(struct fpm_worker_pool_config_s, group) },
 		{ XML_CONF_SCALAR,		"chroot",						&xml_conf_set_slot_string,					offsetof(struct fpm_worker_pool_config_s, chroot) },

Modified: php/php-src/trunk/sapi/fpm/fpm/fpm_conf.h
===================================================================
--- php/php-src/trunk/sapi/fpm/fpm/fpm_conf.h	2010-04-20 20:02:32 UTC (rev 298235)
+++ php/php-src/trunk/sapi/fpm/fpm/fpm_conf.h	2010-04-20 21:13:40 UTC (rev 298236)
@@ -50,7 +50,8 @@
 	char *name;
 	char *listen_address;
 	struct fpm_listen_options_s *listen_options;
-	struct key_value_s *php_defines;
+	struct key_value_s *php_values;
+	struct key_value_s *php_admin_values;
 	char *user;
 	char *group;
 	char *chroot;

Modified: php/php-src/trunk/sapi/fpm/fpm/fpm_php.c
===================================================================
--- php/php-src/trunk/sapi/fpm/fpm/fpm_php.c	2010-04-20 20:02:32 UTC (rev 298235)
+++ php/php-src/trunk/sapi/fpm/fpm/fpm_php.c	2010-04-20 21:13:40 UTC (rev 298236)
@@ -20,7 +20,7 @@
 #include "fpm_cleanup.h"
 #include "fpm_worker_pool.h"

-static int zend_ini_alter_master(char *name, int name_length, char *new_value, int new_value_length, int stage TSRMLS_DC) /* {{{ */
+static int fpm_php_zend_ini_alter_master(char *name, int name_length, char *new_value, int new_value_length, int mode, int stage TSRMLS_DC) /* {{{ */
 {
 	zend_ini_entry *ini_entry;
 	char *duplicate;
@@ -32,10 +32,11 @@
 	duplicate = strdup(new_value);

 	if (!ini_entry->on_modify
-		|| ini_entry->on_modify(ini_entry, duplicate, new_value_length,
-			ini_entry->mh_arg1, ini_entry->mh_arg2, ini_entry->mh_arg3, stage TSRMLS_CC) == SUCCESS) {
+			|| ini_entry->on_modify(ini_entry, duplicate, new_value_length,
+				ini_entry->mh_arg1, ini_entry->mh_arg2, ini_entry->mh_arg3, stage TSRMLS_CC) == SUCCESS) {
 		ini_entry->value = duplicate;
 		ini_entry->value_length = new_value_length;
+		ini_entry->modifiable = mode;
 	} else {
 		free(duplicate);
 	}
@@ -73,55 +74,62 @@
 }
 /* }}} */

-static int fpm_php_apply_defines(struct fpm_worker_pool_s *wp) /* {{{ */
+int fpm_php_apply_defines_ex(struct key_value_s *kv, int mode) /* {{{ */
 {
 	TSRMLS_FETCH();
-	struct key_value_s *kv;

-	for (kv = wp->config->php_defines; kv; kv = kv->next) {
-		char *name = kv->key;
-		char *value = kv->value;
-		int name_len = strlen(name);
-		int value_len = strlen(value);
+	char *name = kv->key;
+	char *value = kv->value;
+	int name_len = strlen(name);
+	int value_len = strlen(value);

-		if (!strcmp(name, "extension") && *value) {
-			zval zv;
+	if (!strcmp(name, "extension") && *value) {
+		zval zv;
+		php_dl(value, MODULE_PERSISTENT, &zv, 1 TSRMLS_CC);
+		return Z_BVAL(zv) ? 1 : -1;
+	}

-#if defined(PHP_VERSION_ID) && (PHP_VERSION_ID >= 50300)
-			php_dl(value, MODULE_PERSISTENT, &zv, 1 TSRMLS_CC);
-#else
-			zval filename;
-			ZVAL_STRINGL(&filename, value, value_len, 0);
-#if (PHP_MAJOR_VERSION >= 5)
-			php_dl(&filename, MODULE_PERSISTENT, &zv, 1 TSRMLS_CC);
-#else
-			php_dl(&filename, MODULE_PERSISTENT, &zv TSRMLS_CC);
-#endif
-#endif
-			continue;
-		}
+	if (fpm_php_zend_ini_alter_master(name, name_len+1, value, value_len, mode, PHP_INI_STAGE_ACTIVATE TSRMLS_CC) == FAILURE) {
+		return -1;
+	}

-		zend_ini_alter_master(name, name_len + 1, value, value_len, PHP_INI_STAGE_ACTIVATE TSRMLS_CC);
+	if (!strcmp(name, "disable_functions") && *value) {
+		char *v = strdup(value);
+		PG(disable_functions) = v;
+		fpm_php_disable(v, zend_disable_function TSRMLS_CC);
+		return 1;
+	}

-		if (!strcmp(name, "disable_functions") && *value) {
-			char *v = strdup(value);
-#if (PHP_MAJOR_VERSION >= 5)
-			PG(disable_functions) = v;
-#endif
-			fpm_php_disable(v, zend_disable_function TSRMLS_CC);
+	if (!strcmp(name, "disable_classes") && *value) {
+		char *v = strdup(value);
+		PG(disable_classes) = v;
+		fpm_php_disable(v, zend_disable_class TSRMLS_CC);
+		return 1;
+	}
+
+	return 1;
+}
+/* }}} */
+
+static int fpm_php_apply_defines(struct fpm_worker_pool_s *wp) /* {{{ */
+{
+	TSRMLS_FETCH();
+	struct key_value_s *kv;
+
+	for (kv = wp->config->php_values; kv; kv = kv->next) {
+		if (fpm_php_apply_defines_ex(kv, ZEND_INI_USER) == -1) {
+			fprintf(stderr, "Unable to set php_value '%s'", kv->key);
 		}
-		else if (!strcmp(name, "disable_classes") && *value) {
-			char *v = strdup(value);
-#if (PHP_MAJOR_VERSION >= 5)
-			PG(disable_classes) = v;
-#endif
-			fpm_php_disable(v, zend_disable_class TSRMLS_CC);
+	}
+
+	for (kv = wp->config->php_admin_values; kv; kv = kv->next) {
+		if (fpm_php_apply_defines_ex(kv, ZEND_INI_SYSTEM) == -1) {
+			fprintf(stderr, "Unable to set php_admin_value '%s'", kv->key);
 		}
 	}

 	return 0;
 }
-/* }}} */

 static int fpm_php_set_allowed_clients(struct fpm_worker_pool_s *wp) /* {{{ */
 {

Modified: php/php-src/trunk/sapi/fpm/fpm/fpm_php.h
===================================================================
--- php/php-src/trunk/sapi/fpm/fpm/fpm_php.h	2010-04-20 20:02:32 UTC (rev 298235)
+++ php/php-src/trunk/sapi/fpm/fpm/fpm_php.h	2010-04-20 21:13:40 UTC (rev 298236)
@@ -9,6 +9,7 @@

 #include "php.h"
 #include "build-defs.h" /* for PHP_ defines */
+#include "fpm/fpm_conf.h"

 struct fpm_worker_pool_s;

@@ -18,6 +19,7 @@
 size_t fpm_php_content_length(TSRMLS_D);
 void fpm_php_soft_quit();
 int fpm_php_init_main();
+int fpm_php_apply_defines_ex(struct key_value_s *kv, int mode);

 #endif


Modified: php/php-src/trunk/sapi/fpm/php-fpm.conf.in
===================================================================
--- php/php-src/trunk/sapi/fpm/php-fpm.conf.in	2010-04-20 20:02:32 UTC (rev 298235)
+++ php/php-src/trunk/sapi/fpm/php-fpm.conf.in	2010-04-20 21:13:40 UTC (rev 298236)
@@ -55,11 +55,21 @@

 			Additional php.ini defines, specific to this pool of workers.
 			These settings overwrite the values previously defined in the php.ini.
-			<value name="php_defines">
+			Like apache, you can use php_value, php_flag, php_admin_value or php_admin_flag.
+			Defining 'extension' will search for the corresponding shared extension in extension_dir.
+			Defining 'disable_functions' or 'disable_classes' won't overwrite previously defined
+			php.ini value, but the new value will be append.
+			<value name="php_value">
+				<!-- <value name="error_log">/var/log/php-error.log</value> -->
+			</value>
+			<value name="php_flag">
+				<!-- <value name="log_errors">true</value> -->
+			</value>
+			<value name="php_admin_value">
 				<!-- <value name="sendmail_path">/usr/sbin/sendmail -t -i</value> -->
+			</value>
+			<value name="php_admin_flag">
 				<!-- <value name="display_errors">0</value> -->
-				<!-- <value name="error_log">/var/log/php-error.log</value> -->
-        		<!-- <value name="log_errors">true</value> -->
 			</value>

 			Unix user of processes
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to