php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #63941
Patch date_perf_patch3.txt revision 2013-01-08 16:02 UTC by njaguar at gmail dot com

Patch date_perf_patch3.txt for Performance problem Bug #63941

Patch version 2013-01-08 16:02 UTC

Return to Bug #63941 | Download this patch
Patch Revisions:

Developer: njaguar@gmail.com

--- php_date.c.orig	2013-01-08 02:07:54.130321618 -0600
+++ php_date.c	2013-01-08 09:44:14.114929567 -0600
@@ -601,7 +601,6 @@
 	date_globals->default_timezone = NULL;
 	date_globals->timezone = NULL;
 	date_globals->tzcache = NULL;
-	date_globals->timezone_valid = 0;
 }
 /* }}} */
 
@@ -855,12 +854,14 @@
 		return FAILURE;
 	}
 
-	DATEG(timezone_valid) = 0;
 	if (stage == PHP_INI_STAGE_RUNTIME) {
 		if (!timelib_timezone_id_is_valid(DATEG(default_timezone), DATE_TIMEZONEDB)) {
-			php_error_docref(NULL TSRMLS_CC, E_WARNING, DATE_TZ_ERRMSG);
+			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid date.timezone value '%s'.", new_value);
 		} else {
-			DATEG(timezone_valid) = 1;
+			if (DATEG(timezone)) {
+				efree(DATEG(timezone));
+			}
+			DATEG(timezone) = estrndup(new_value, new_value_length);
 		}
 	}
 
@@ -872,34 +873,23 @@
 static char* guess_timezone(const timelib_tzdb *tzdb TSRMLS_DC)
 {
 	/* Checking configure timezone */
-	if (DATEG(timezone) && (strlen(DATEG(timezone))) > 0) {
+	if (DATEG(timezone) && *DATEG(timezone)) {
 		return DATEG(timezone);
-	}
-	/* Check config setting for default timezone */
-	if (!DATEG(default_timezone)) {
+	} else {
 		/* Special case: ext/date wasn't initialized yet */
+		if (DATEG(timezone)) { /* should never happen, but just in case */
+			efree(DATEG(timezone));
+		}
 		zval ztz;
-
 		if (SUCCESS == zend_get_configuration_directive("date.timezone", sizeof("date.timezone"), &ztz)
 			&& Z_TYPE(ztz) == IS_STRING && Z_STRLEN(ztz) > 0 && timelib_timezone_id_is_valid(Z_STRVAL(ztz), tzdb)) {
-			return Z_STRVAL(ztz);
-		}
-	} else if (*DATEG(default_timezone)) {
-		if (DATEG(timezone_valid) == 1) {
-			return DATEG(default_timezone);
-		}
-
-		if (!timelib_timezone_id_is_valid(DATEG(default_timezone), tzdb)) {
-			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid date.timezone value '%s', we selected the timezone 'UTC' for now.", DATEG(default_timezone));
-			return "UTC";
+		    DATEG(timezone) = estrndup(Z_STRVAL(ztz), Z_STRLEN(ztz));
+		} else {
+			php_error_docref(NULL TSRMLS_CC, E_WARNING, DATE_TZ_ERRMSG "Invalid date.timezone value '%s'. We selected the timezone 'UTC' for now.", Z_STRVAL(ztz));
+			DATEG(timezone) = estrdup("UTC");
 		}
-
-		DATEG(timezone_valid) = 1;
-		return DATEG(default_timezone);
 	}
-	/* Fallback to UTC */
-	php_error_docref(NULL TSRMLS_CC, E_WARNING, DATE_TZ_ERRMSG "We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone.");
-	return "UTC";
+	return DATEG(timezone);
 }
 
 PHPAPI timelib_tzinfo *get_timezone_info(TSRMLS_D)
@@ -4024,7 +4014,6 @@
 	}
 	if (DATEG(timezone)) {
 		efree(DATEG(timezone));
-		DATEG(timezone) = NULL;
 	}
 	DATEG(timezone) = estrndup(zone, zone_len);
 	RETURN_TRUE;
--- php_date.h.orig	2013-01-08 02:07:49.011426110 -0600
+++ php_date.h	2013-01-08 02:14:45.094321790 -0600
@@ -150,11 +150,10 @@
 };
 
 ZEND_BEGIN_MODULE_GLOBALS(date)
-	char                    *default_timezone;
-	char                    *timezone;
+	char                    *default_timezone; /* ini timezone value */
+	char                    *timezone; /* runtime timezone value */
 	HashTable               *tzcache;
 	timelib_error_container *last_errors;
-	int                     timezone_valid;
 ZEND_END_MODULE_GLOBALS(date)
 
 #ifdef ZTS
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 05:01:33 2024 UTC