Jump to content
sylvest

Times Reported By Server In Php Don't Recognise Dst

Recommended Posts

Hi,

The web pages that I am currently writing (in PHP) report errors including a timestamp to the file /home/xxxxxxx/logs/main.log. The times reported are UTC. I have the following in my PHP:
date_default_timezone_set("Europe/London");
which I believe should set it to use the stated timezone throughout my site, which should (I think) recognise DST, so should now report UTC +01:00. It is not doing so.
I thave changed the PHP code that writes to the log file to this:
$logmsg = gmdate("[d-M-Y H:i:s e I P T] ") . "on " . $hostname . " " ....
and it is now outputting:
[06-Apr-2017 16:19:50 UTC 0 +00:00 GMT] on localhost L_TRACE at line 96 ....

from which you can see that it thinks it is outputting UTC. I think the problem is that it is just not switching to the timezone I have requested.

Please can you suggest why it is not outputting GMT/DST, i.e. UTC +01:00, or what I need to do to find out what is causing this problem?

Thank you - Rowan

Edited by TCH-Bala
edited out username

Share this post


Link to post
Share on other sites

Hi Rowan,

 

 

This issue should now be resolved. Your local version of php.ini (/home/USERNAME/php.ini) was overriding the date_default_timezone_set function. I have changed date.timezone value in that file to "Europe/London". Could you please try again and let me know if the problem persists?

Share this post


Link to post
Share on other sites

Bryan,

 

Thanks for your help with this. Now the system error log is reporting the correct time in GMT with DST, but the PHP log is still reporting GMT without DST. I have removed all the calls to date_default_timezone_set() in my PHP files but it is still the same. To generate the PHP log my code is:

$logmsg = gmdate("[d-M-Y H:i:s e I P T] ") . "on " . $hostname . " " . $loglevels[$level] . " " . $msg . " at line " . $line . " in file " . $file . PHP_EOL;

The text produced in the log file is (example):

[10-Apr-2017 11:47:18 UTC 0 +00:00 GMT] on localhost L_TRACE Redirecting to Location: http://www.sylvesterbradley.org/swchoir/welcome.php using header at line 302 in file /home/xxx/include/initialise.php

Any idea why it is doing this, or what I can do to correct it?

 

Please can you explain how the date.timezone = in the PHP.ini file interacts with the date_default_timezone_set() in a PHP file. Does one override the other? Which takes precedence? Or if I use one, does using the other cause an error? Which way round?

 

Ideally I would like the PHP file to determine which timezone it uses, if necesary overriding what is written in the PHP.ini file, since one section of the web site may require a different timezone than another. Or I may want to reflect the timezone of the particular user that has logged on.

 

Thanks - Rowan

Edited by TCH-Bala
Please do not add sensitive information like domain and home directory paths on a public forum

Share this post


Link to post
Share on other sites

Scripts default to the php parameters including timezone as set on the server's php.ini config. If you set a local php.ini (this needs to be set via cpanel -> MultiPHP INI Editor), then the default values will be overridden by what is set on the local ini file.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×