summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Strojny <lstrojny@php.net>2013-01-06 03:06:09 +0100
committerLars Strojny <lstrojny@php.net>2013-01-06 03:06:09 +0100
commit67557fcfcea2c22e9b8d9f0ba86f461c02002cb7 (patch)
treeaac37319309f6d840eba6fed66916a47a5ebea2b
parent2feea39a3320d100bae8a1193aba9022726a24ea (diff)
downloadphp-git-67557fcfcea2c22e9b8d9f0ba86f461c02002cb7.tar.gz
Bug #63699: performance improvements for varios ext/date functions
-rw-r--r--NEWS4
-rw-r--r--ext/date/php_date.c47
-rw-r--r--ext/date/php_date.h7
3 files changed, 47 insertions, 11 deletions
diff --git a/NEWS b/NEWS
index 91b7b46637..75c981681f 100644
--- a/NEWS
+++ b/NEWS
@@ -34,6 +34,10 @@ PHP NEWS
. Fixed bug #55438 (Curlwapper is not sending http header randomly).
(phpnet@lostreality.org, Pierrick)
+- Date:
+ . Fixed bug #63699 (Performance improvements for various ext/date functions).
+ (Lars, original patch by njaguar at gmail dot com)
+
20 Dec 2012, PHP 5.4.10
- Core:
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index ac119a35d5..1837f94520 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -495,9 +495,11 @@ int php_date_global_timezone_db_enabled;
/* 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)
@@ -599,6 +601,7 @@ static PHP_GINIT_FUNCTION(date)
date_globals->default_timezone = NULL;
date_globals->timezone = NULL;
date_globals->tzcache = NULL;
+ date_globals->timezone_valid = 0;
}
/* }}} */
@@ -844,25 +847,53 @@ timelib_tzinfo *php_date_parse_tzfile_wrapper(char *formal_tzname, const timelib
}
/* }}} */
+// 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(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);
+ } else {
+ DATEG(timezone_valid) = 1;
+ }
+ }
+
+ return SUCCESS;
+}
+/* }}} */
+
/* {{{ Helper functions */
static char* guess_timezone(const timelib_tzdb *tzdb TSRMLS_DC)
{
/* Checking configure timezone */
- if (DATEG(timezone) && (strlen(DATEG(timezone)) > 0)) {
+ if (DATEG(timezone) && strlen(DATEG(timezone)) > 0) {
return DATEG(timezone);
}
/* Check config setting for default timezone */
if (!DATEG(default_timezone)) {
/* Special case: ext/date wasn't initialized yet */
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)) {
+
+ 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) && timelib_timezone_id_is_valid(DATEG(default_timezone), tzdb)) {
+ } else if (*DATEG(default_timezone)) {
+ if (DATEG(timezone_valid) == 1) { // timezone already checked and validated
+ 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_valid) = 1;
return DATEG(default_timezone);
}
/* Fallback to UTC */
diff --git a/ext/date/php_date.h b/ext/date/php_date.h
index c9c165050a..f0b662b5d9 100644
--- a/ext/date/php_date.h
+++ b/ext/date/php_date.h
@@ -150,10 +150,11 @@ struct _php_period_obj {
};
ZEND_BEGIN_MODULE_GLOBALS(date)
- char *default_timezone;
- char *timezone;
- HashTable *tzcache;
+ char *default_timezone;
+ char *timezone;
+ HashTable *tzcache;
timelib_error_container *last_errors;
+ int timezone_valid;
ZEND_END_MODULE_GLOBALS(date)
#ifdef ZTS