skip to Main Content

I have a dev environment and a production environment. The time() function returns the correct timestamp in my dev env but in my production environment time() is exactly 59 seconds behind!
The version of PHP is 7.0.3 on both environments.
This can’t be a timezone issue since the difference is only one minute and the PHP default timezone is the same in both environments (America/Los Angeles).
It is now 10:48:29 am and here is the output from calling this function simultaneously in both environments (or at least as fast as I can press enter on the console).

Dev environment (is correct)

php > echo date('h:i:s A');
10:48:29 AM

Production environment (is one minute behind)

echo date('h:i:s A');
10:47:31 AM

Same happens with the time() function

Dev environment (is correct)

php > echo time();
1568742851

Production environment (is one minute behind)

echo time();
1568742792

And 1568742851 – 1568742792 = 59 secs

I know i could just add 59 seconds to the timestamp time() returns but that just seems like a hack and does not solve the problem. I would like to please get advice as to how to fix my production environment.

2

Answers


  1. Confirm that you are allowing NTP traffic to your production OS environment. You can confirm that your server is properly communicating to NTP by running the following command ntpq -c peers If you receive a Connection refused prompt you don’t have proper connectivity. You will need to configure an inbound firewall rule allowing UDP traffic on port 123. Once this is done, restart your NTP service service ntpd restart and rerun the ntpq -c peers command

    Login or Signup to reply.
  2. I believe the system clock on your production and dev machine is unsync, Regardless of the version of PHP or Operating System, Just like @g_bor mentioned in comment.

    Don’t get confused by the time zone, Just run the command date +%s on system shell to print timestamp on both machines, If you have no permission (can’t login with ssh), You can prepare the PHP file which contains system('date +%s');, And then, Upload to your web server and open the browser to check the timestamps on both your machines.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search