Re: Re: PHP 4.0 Bug #7203 Updated: Lack of calling tzset() in some php internal code

From: Date: Sun, 07 Jan 2001 05:35:37 +0000
Subject: Re: Re: PHP 4.0 Bug #7203 Updated: Lack of calling tzset() in some php internal code
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-43199@lists.php.net to get a copy of this message
After investigating this a bit I think calling tzset() every time when you use time related functions is not good thing (tm) to do. Actually, it should ONLY be called when the TZ environment variable is changed. Some manual pages say, that the time conversion functions call tzset() automaticly. Well, they SHOULD call it but for some reason they don't do it always. This patch seem to fix these problems (at least for me) and I'm going to commit it if nobody objects: Index: basic_functions.c =================================================================== RCS file: /repository/php4/ext/standard/basic_functions.c,v retrieving revision 1.291 diff -u -r1.291 basic_functions.c --- basic_functions.c 2000/12/27 15:43:05 1.291 +++ basic_functions.c 2001/01/07 05:23:08 @@ -1029,6 +1029,9 @@ if ((ret=putenv(pe.putenv_string))==0) { /* success */ zend_hash_add(&BG(putenv_ht),pe.key,pe.key_len+1,(void **) &pe,sizeof(putenv_entry),NULL); +#ifdef HAVE_TZSET + if(!strncmp(pe.key,"TZ",2)) tzset(); +#endif RETURN_TRUE; } else { efree(pe.putenv_string); On Wed, 3 Jan 2001, Christian Robert wrote: > >well, I means in php_strftime() > >here a piece of code from ext/standard/datetime.c > >---------------------------------------------------------- >#if HAVE_STRFTIME >void _php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gm) >{ > pval **format_arg, **timestamp_arg; > char *format,*buf; > time_t timestamp; > struct tm *ta, tmbuf; > int max_reallocs = 5; > size_t buf_len=64, real_len; > > tzset(); /* Bug fix, Xtian */ > > switch (ZEND_NUM_ARGS()) { > case 1: >----------------------------------------------------------- > >the tzset() call is what I added to the code in php 4.0.3 >to fix the bug. It should probably be surrounded by > > #ifdef HAVE_TZSET > tzset(); > #endif > >thanks, >Xtian. > > > >Bug Database wrote: >> >> ID: 7203 >> Updated by: derick >> Reported By: christian.robert@polymtl.ca >> Old-Status: Open >> Status: Assigned >> Bug Type: Date/time related >> Assigned To: derick >> Comments: >> >> The tzset documentation on Linux says this: >> The tzset() function initializes the tzname variable from >> the TZ environment variable. This function is automati­ >> cally called by the other time conversion functions that >> depend on the time zone. >> >> But strftime is really a libc thingy, and is not emulated in PHP. >> >> Please also try php 4.0.4, there where some fixes in it that had to do with date and time >> stuff. >> >> Previous Comments: >> --------------------------------------------------------------------------- >> >> [2000-10-14 04:27:04] christian.robert@polymtl.ca >> I recently found a problem on a php piece of code >> who looks like: >> >> putenv("TZ=$Some_TZ"); // Like "EST5EDT" >> $val= strftime("%Z"); >> echo "Timezone = ".$val; >> >> It sometimes get the right value, sometimes some "near" garbage >> values. Not repeateable (at random under apache). >> >> it looks like that under standard linux(glibc2), all "time" related function >> should call "C" function tzset() before first usage. >> >> I see in the source that: _php_mktime() is calling tzset() #if HAVE_TZSET >> >> the strftime() function need this too (for linux at least) >> >> thanks, >> Xtian. >> >> --------------------------------------------------------------------------- >> >> Full Bug description available at: >> http://bugs.php.net/?id=7203 > >

« previous php.dev (#43199) next »