I write some events on the server to the log and noticed that the number of each month is recorded incorrectly on the first day of each month. Back in the twenties of December 1 recorded. Here is the code:

date_default_timezone_set('Europe/Moscow'); $date = date('Ym-d'); $time = date('H:i:s'); file_put_contents("log.txt", $date."\t".$time, FILE_APPEND); 

Result:

 2016-11-24 11:35:07 2016-12-01 01:22:42 2016-12-01 04:48:42 2016-11-25 22:03:59 ... 2016-11-30 19:13:23 2016-11-30 19:20:06 2016-12-06 08:16:38 2016-12-06 22:14:27 

What could be the problem?

  • 3
    I can only say that it is very, very strange. Look at the other logs on the server - if the date was not lost there. - cronfy

1 answer 1

Note that in Debian / Ubuntu, this function will return the system time zone defined in / etc / localtime if date.timezone is not defined, even with PHP 5.4+. Watch here

You can follow the code as follows:

 file_put_contents("log.txt", $date."\t".$time.'\t'. date_default_timezone_get(), FILE_APPEND); 

Or this option:

 <?php date_default_timezone_set('Europe/Moscow'); $script_tz = date_default_timezone_get(); if (strcmp($script_tz, ini_get('date.timezone'))){ echo 'Временная зона скрипта отличается от заданной в INI-файле.'; } else { echo 'Временные зоны скрипта и настройки INI-файла совпадают.'; } ?> 

If you are interested in a complete list of the configuration settings of your system with the current values, then you can run the phpinfo () function and get the resulting page. You can also access the values ​​of individually configured directives during execution using ini_get () or get_cfg_var () .

Good luck!