Commit: f3824ad16644c53645e7428d2e838278f5a0e1c4 Author: Lars Strojny <lstro...@php.net> Sun, 6 Jan 2013 02:10:16 +0100 Parents: f85e5950ab4552799c119cd1d23617535ed19e61 Branches: PHP-5.5
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=f3824ad16644c53645e7428d2e838278f5a0e1c4 Log: Bug #63699 performance improvements for ext/date by only validating timezone when timezone is set Bugs: https://bugs.php.net/63699 Changed paths: M ext/date/php_date.c M ext/date/php_date.h Diff: diff --git a/ext/date/php_date.c b/ext/date/php_date.c index c564710..b4819ab 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; } /* }}} */ @@ -843,35 +846,57 @@ 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)) { - if (timelib_timezone_id_is_valid(DATEG(default_timezone), tzdb)) { + if (DATEG(timezone_valid) == 1) { // timezone already checked and validated return DATEG(default_timezone); } - /* Invalid date.timezone value */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid date.timezone value '%s', we selected the timezone 'UTC' for now.", DATEG(default_timezone)); - } else { - /* No date.timezone value */ - 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."); + + 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 */ + 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"; } @@ -889,6 +914,7 @@ PHPAPI timelib_tzinfo *get_timezone_info(TSRMLS_D) } /* }}} */ + /* {{{ date() and gmdate() data */ #include "ext/standard/php_smart_str.h" diff --git a/ext/date/php_date.h b/ext/date/php_date.h index c9c1650..f0b662b 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 -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php