Bug #25825 [Com]: Windows PHP always returns UTC time and BST as the timezone

From: Date: Sun, 11 May 2014 12:09:18 +0000
Subject: Bug #25825 [Com]: Windows PHP always returns UTC time and BST as the timezone
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185757@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=25825&edit=1 ID: 25825 Comment by: anshuman_chatterjee14 at yahoo dot com Reported by: pennington at rhodes dot edu Summary: Windows PHP always returns UTC time and BST as the timezone Status: Closed Type: Bug Package: Date/time related Operating System: Windows 2000 PHP Version: 4.3.3 Assigned To: wez Block user comment: N Private report: N New Comment: The Problem is too common as PHP data time function calls GMT time not our specific time zone time....\ i too faced the problem.. there is a simple answer to it... use strtotime('+ 5 hour 30 minute') // your time zone mine id IST = GMT + 5:30 instead of time(); so to obtain a full time you do the following. date("l-jS-F-Y g:i:s A", strtotime('+ 5 hour 30 minute')) = Sunday-11th-May-2014 5:32:30 PM as answer..... Previous Comments: ------------------------------------------------------------------------ [2003-10-14 20:24:23] wez@php.net This bug has been fixed in CVS. In case this was a PHP problem, snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. In case this was a documentation problem, the fix will show up soon at http://www.php.net/manual/. In case this was a PHP.net website problem, the change will show up on the PHP.net site and on the mirror sites in short time. Thank you for the report, and for helping us make PHP better. The problem was that putenv("TZ=...") would call tzset() in order to update the libc with the timezone information for the time related functions, but PHP would not call tzset() again when the environment was reset. I've checked in a fix for this problem, which should hopefully make things better. However, a word of warning: The environmental variables are process-wide, so changing them in a threaded environment like ISAPI may cause some gotchas in high-concurrency scenarios (eg: two threads might be playing with the same env var at the same time). I'm marking this report as closed as the next snapshots will contain the fix. If the problem is still present in those, please reopen this report. ------------------------------------------------------------------------ [2003-10-14 18:37:33] wez@php.net Yes; that is what is happening. I'll look into having PHP reset to the system default locale at the start of each request. ------------------------------------------------------------------------ [2003-10-14 14:22:09] pennington at rhodes dot edu Ahh, the TikiWiki PHP application (in /lib/date/TimeZone.php) that we are running does use putenv() in the following function: ---------------- /** * Is the given date/time in DST for this time zone * * Attempts to determine if a given Date object represents a date/time * that is in DST for this time zone. WARNINGS: this basically attempts to * "trick" the system into telling us if we're in DST for a given time zone. * This uses putenv() which may not work in safe mode, and relies on unix time * which is only valid for dates from 1970 to ~2038. This relies on the * underlying OS calls, so it may not work on Windows or on a system where * zoneinfo is not installed or configured properly. * * @access public * @param object Date $date the date/time to test * @return boolean true if this date is in DST for this time zone */ function inDaylightTime($date) { $env_tz = ""; if(getenv("TZ")) { $env_tz = getenv("TZ"); } putenv("TZ=".$this->id); $ltime = localtime($date->getTime(), true); putenv("TZ=".$env_tz); return $ltime['tm_isdst']; } ------------------- Are you saying that this could change the environment variable for timezone for the entire server for good (at least until IIS5 is restarted) once this code is executed? And this would affect pages that don't even include the function above? ------------------------------------------------------------------------ [2003-10-14 12:15:49] iliaa@php.net The only other way to manipulate locale is via putenv(), which would change LC_* environment variable. ------------------------------------------------------------------------ [2003-10-14 10:29:48] pennington at rhodes dot edu I searched through all of the PHP code in use on this machine for the setlocale() function and only found two entries, both of which were commented out. The only ISAPI filter we are using is PHP, and there is no ASP or other code on that machine. In other words, we are only using it to serve PHP pages, and none of those scripts use setlocale(). Would it be wise to unload the ASP stuff from the app mappings in IIS5 if we aren't using it so we can test to rule out ASP as the problem? Are there any other PHP functions (other than setlocale) that manipulate the locale? ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=25825 -- Edit this bug report at https://bugs.php.net/bug.php?id=25825&edit=1

« previous php.bugs (#185757) next »