Skip to content
Browse files

Bug #63699: performance improvements for varios ext/date functions

  • Loading branch information...
1 parent 2feea39 commit 67557fcfcea2c22e9b8d9f0ba86f461c02002cb7 @lstrojny lstrojny committed Jan 6, 2013
Showing with 47 additions and 11 deletions.
  1. +4 −0 NEWS
  2. +39 −8 ext/date/php_date.c
  3. +4 −3 ext/date/php_date.h
View
4 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:
View
47 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 */
View
7 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

0 comments on commit 67557fc

Please sign in to comment.
Something went wrong with that request. Please try again.