php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #29654 Different timezone's time is stored in Apache process for other requests
Submitted: 2004-08-13 16:51 UTC Modified: 2007-05-21 11:16 UTC
From: kulakov74 at yandex dot ru Assigned: derick (profile)
Status: Closed Package: Feature/Change Request
PHP Version: 4.3.7 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: kulakov74 at yandex dot ru
New email:
PHP Version: OS:

 

 [2004-08-13 16:51 UTC] kulakov74 at yandex dot ru
Description:
------------
I tried putenv('TZ=...') to get local time for any timezone. After that, if I don't call putenv('TZ=...') using date/time functions (date()) in consequent requests randomly return either local time or the time for the zone last set with TZ. In Apache access_log's time offsets also vary. It seems that Apache proccesses remember the time for the timezone set with TZ and use it for consequent requests. 

Unfortunately, there's no function for deleting an environment variable. Even though with consequent requests TZ seems to be undefined, date functions work as if it were set for the last value. 

For a reason, calling mktime(0,0,0,1,1,1970) clears Apache's processes internal time, but that happens only on subsequent requests, not within the same one. 

Of course, one can use putenv('TZ=...') for setting local timezone back after working with a different timezone, but anyway I guess that shouldn't be the way it is. 

We use Apache 2. 

Reproduce code:
---------------
//first request:
echo(date('H:i:s').'<BR>'); //localtime
putenv('TZ=Europe/Moscow');
echo(date('H:i:s').'<BR>'); //Moscow time - works okay

//at consequent requests:
echo(date('H:i:s').'<BR>'); //may produce local or Moscow time, depending on which Apache process handles the request

Expected result:
----------------
see above

Actual result:
--------------
see above

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-08-16 08:37 UTC] derick@php.net
But you DO need to set it back immediately as the function modifies the environment which is also used by requests to the same apache child. No bug here.
 [2004-09-03 10:58 UTC] kulakov74 at yandex dot ru
Thanks for the answer, there's certainly no bug here, but I want to make it a feature request this way: the fact that there's no way to unset an environment variable makes it impossible to recover the initial state when there's no timezone set. Note that when TZ is not set and when it is set to an empty string are two different things - the first uses the locale of the server, while the second uses GMT. In this situation the only way to leave the process with the correct timezone is to set it directly, but then one has to know it, and this is not very convenient. First of all, you can't just have a piece of code that does all the task - whenever you deploy it to another server you have to somehow tell it the server's timezone - either via config files or by hardcoding; after all, one may just forget it. What I mean is that PHP badly lacks a function for unsetting environment variables.
 [2004-09-03 11:52 UTC] derick@php.net
The feature request is already on my todo, should be in 5.1.
 [2005-06-20 09:43 UTC] derick@php.net
This bug has been fixed in CVS.

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/.
 
Thank you for the report, and for helping us make PHP better.

This is implemented (partly) in PHP 5.1 by adding a new configure setting "date.timezone" that configures the default timezone for all date functions.
 [2007-05-21 11:16 UTC] kulakov74 at yandex dot ru
Though this is an old issue, I had to revisit it, and I found:
1. I can delete an env. var. by putenv('TZ') - a user comment explains that, but the docs does not
2. I cannot reproduce the problem any more - even if I leave the wrong timezone it never shows in consequent requests. Note that the version is 4.1.2. Perhaps something has changed in PHP but I can't test it!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 02 15:01:30 2024 UTC