Re: com php-src: Bug #63699: performance improvements for varios ext/date functions: NEWS ext/date/php_date.c ext/date/php_date.h

From: Date: Sun, 06 Jan 2013 15:08:37 +0000
Subject: Re: com php-src: Bug #63699: performance improvements for varios ext/date functions: NEWS ext/date/php_date.c ext/date/php_date.h
References: 1  Groups: php.cvs 
Request: Send a blank email to php-cvs+get-70873@lists.php.net to get a copy of this message
Nice! I have another suggestion to further improve the performance: make OnUpdate_date_timezone() update both 'timezone' and 'default_timezone'. The variable 'timezone_valid' can then be removed altogether. Thanks, Nuno P.S.: I know it was already there but while at it, can you please change 'strlen(DATEG(timezone)) > 0' to '*DATEG(timezone)'. ----- Original Message ----- From: "Lars Strojny" <lstrojny@php.net> To: <php-cvs@lists.php.net> Sent: Sunday, January 06, 2013 2:06 AM Subject: [PHP-CVS] com php-src: Bug #63699: performance improvements for varios ext/date functions: NEWS ext/date/php_date.c ext/date/php_date.h
Commit:    67557fcfcea2c22e9b8d9f0ba86f461c02002cb7
Author:    Lars Strojny <lstrojny@php.net>         Sun, 6 Jan 2013 03:06:09 +0100
Parents: 2feea39a3320d100bae8a1193aba9022726a24ea Branches: PHP-5.4 Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=67557fcfcea2c22e9b8d9f0ba86f461c02002cb7 Log: Bug #63699: performance improvements for varios ext/date functions Bugs: https://bugs.php.net/63699 Changed paths: M NEWS M ext/date/php_date.c M ext/date/php_date.h Diff: diff --git a/NEWS b/NEWS index 91b7b46..75c9816 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 ac119a3..1837f94 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 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

« previous php.cvs (#70873) next »