Problem with wrong time in PHP (America / Sao_Paulo)

2

I'm running an application running in a CentOS production environment with PHP and Apache updated.

I noticed that CakePHP's logs return a wrong time from the one defined in php.ini and also set inside the application's Bootstrap by date_default_timezone_set(..) .

In both the logs and in the PHP date the returned time is always 2 hours less .

For example, it is now 3:35 pm and php returns as:

20/01/2015 13:35:10 America / Sao_Paulo BRST

The date of the operating system is in order, shows on the right date, runs the cronons at the right time as well.

What could be happening?

    
asked by anonymous 20.01.2015 / 18:37

2 answers

3

Throughout the description of the problem I read I understand that there is only one misinterpretation of how to use the date.

My understanding is that the server has the right time, at least its examples match the Brazilian time at the time you post. You are interpreting that the time is in GMT which is universal time, but the server time is in Brazil\East time, it is using -0200 . GMT uses 0000 . Because the server interprets that it is in GMT, any attempt to use another timezone will result in a 2 hour error. So if the server time is already the time you want, you can not use another timezone other than GMT.

Another possible interpretation is that the time of the server is wrong, since it is with the time of Brazil but is indicating that the time is GMT. In fact, analyzing strictly, it is wrong indeed. When you say precisely at 18:09 GMT your server shows 18:09 GMT indicates that it is wrong, because at 18:09 GMT the correct GMT is 20:09.

You have a few options:

  • If you want to use Brazilian time on the server, set the timezone of the server to be BRST (you will have to adjust for BRT when the daylight saving time ends, if the server does not do it automatically). >
  • If you want to keep using GMT, set the correct time for now, set London time, and not ours.
  • Or leave it as it is and stop setting up other software to use another timezone , since what is on the server is exactly the time you want. That is, stop setting PHP, either in ini , or with the date_default_timezone_set function.

This last solution is not the right one. If you have any software that you can not control timezone , it will give you trouble. In compensation it is the only form of poorly made software that does not consider timezone to work properly.

See a server with all correct (although the time is not there so well synchronized at the time I tested :))

    
21.01.2015 / 01:38
0

I do not use CakePHP, but with a query in google, I reached question in the English StackOverflow that talks about setting timezone in the config/core.php file in the application folder.

    
20.01.2015 / 18:50