php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #63699
Patch date_perf_patch2 revision 2012-12-05 15:53 UTC by njaguar at gmail dot com

Patch date_perf_patch2 for Performance problem Bug #63699

Patch version 2012-12-05 15:53 UTC

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

Developer: njaguar@gmail.com

diff -Naur src/php-5.4.9_orig/ext/date/php_date.c src/php-5.4.9/ext/date/php_date.c
--- src/php-5.4.9_orig/ext/date/php_date.c	2012-11-20 23:12:20.000000000 -0600
+++ src/php-5.4.9/ext/date/php_date.c	2012-12-05 03:44:54.233103975 -0600
@@ -495,9 +495,11 @@
 /* on 90'35; common sunrise declaration (sun body disappeared) */
 #define DATE_SUNRISE_ZENITH "90.583333"
 
+static PHP_INI_MH(OnUpdate_date_timezone);
+
 /* {{{ INI Settings */
 PHP_INI_BEGIN()
-	STD_PHP_INI_ENTRY("date.timezone", "", PHP_INI_ALL, OnUpdateString, default_timezone, zend_date_globals, date_globals)
+	STD_PHP_INI_ENTRY("date.timezone", "", PHP_INI_ALL, OnUpdate_date_timezone, default_timezone, zend_date_globals, date_globals)
 	PHP_INI_ENTRY("date.default_latitude",           DATE_DEFAULT_LATITUDE,        PHP_INI_ALL, NULL)
 	PHP_INI_ENTRY("date.default_longitude",          DATE_DEFAULT_LONGITUDE,       PHP_INI_ALL, NULL)
 	PHP_INI_ENTRY("date.sunset_zenith",              DATE_SUNSET_ZENITH,           PHP_INI_ALL, NULL)
@@ -597,6 +599,7 @@
 	date_globals->default_timezone = NULL;
 	date_globals->timezone = NULL;
 	date_globals->tzcache = NULL;
+	date_globals->tz_checked_valid = 0;
 }
 /* }}} */
 
@@ -842,6 +845,27 @@
 }
 /* }}} */
 
+// created this callback method to check the date.timezone only when changed, to increase performance and error on an ini_set line
+/* {{{ static PHP_INI_MH(OnUpdate_date_timezone) */
+static PHP_INI_MH(OnUpdate_date_timezone)
+{
+        if (OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC) == FAILURE) {
+                return FAILURE;
+        }
+
+	DATEG(tz_checked_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);
+		} else {
+			DATEG(tz_checked_valid) = 1;
+		}
+        }
+
+        return SUCCESS;
+}
+/* }}} */
+
 /* {{{ Helper functions */
 static char* guess_timezone(const timelib_tzdb *tzdb TSRMLS_DC)
 {
@@ -860,8 +884,13 @@
 		    timelib_timezone_id_is_valid(Z_STRVAL(ztz), tzdb)) {
 			return Z_STRVAL(ztz);
 		}
-	} else if (*DATEG(default_timezone) && timelib_timezone_id_is_valid(DATEG(default_timezone), tzdb)) {
-		return DATEG(default_timezone);
+	} else if (*DATEG(default_timezone)) {
+		if (DATEG(tz_checked_valid)==1) { // timezone already checked and validated
+			return DATEG(default_timezone);
+		} else if (timelib_timezone_id_is_valid(DATEG(default_timezone), tzdb)) {
+			DATEG(tz_checked_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.");
diff -Naur src/php-5.4.9_orig/ext/date/php_date.h src/php-5.4.9/ext/date/php_date.h
--- src/php-5.4.9_orig/ext/date/php_date.h	2012-11-20 23:12:20.000000000 -0600
+++ src/php-5.4.9/ext/date/php_date.h	2012-12-05 03:22:05.308104021 -0600
@@ -153,6 +153,7 @@
 	char      *default_timezone;
 	char      *timezone;
 	HashTable *tzcache;
+	char      tz_checked_valid;
 	timelib_error_container *last_errors;
 ZEND_END_MODULE_GLOBALS(date)
 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC