Tutorial

Have you ever wondered what the exact time your hosts web server happens to be going by? How about PHP time? And, are they exactly the same or different?

In some situations you may have purposely configured a php.ini file with a date.timezone that happens to be different from the actual server time zone.

For instance maybe you updated or added the following:
date.timezone = America/Los_Angeles

But, the server time is actually set for America/Chicago. This sometimes leads to confusion with things like email, cron jobs, etc.

Your php script is using one time for your website, but server side processes like email and cron reflect and happen at another time.

If you want to check your server to see the exact time they happen to be going by you can create a simple file with the following:

<?php
$today = date("F j, Y, g:i a");
echo $today;
echo "<br>".shell_exec("date");
?>

Just copy and paste that into notepad and save it as time-test.php. Then, upload it to your hosting account and visit the page with your web browser like:
http://www.yoursite.com/time-test.php

It will output the PHP Time on the first line, and the server time on the second, which looks something like this:

PHP Time and Server Time



As you can see in this screenshot the top line (PHP Time) is 5:33 PM, and the second line (Server Time) is 16:33 (MST), which is actually 4:33 PM. So it's actually one hour ahead of the server time. It is also important to note that MST is Mountain Standard Time.

You could use this information to sync the two. With shared hosting you can't change the system time, but many hosts will allow you to create php.ini files. If you want the two to reflect the same time you would just open php.ini or create one and add the line:
date.timezone = America/Chicago

Or, any other time zone (Area/City) that you need to make them match.

You can find a complete list of supported timezones here:
http://php.net/manual/en/timezones.php

This is a nice little script, which might come in handy for you at some point.

When you are done testing simply remove/delete the time-test.php file from your hosting account. Keep it in a safe place on your local computer for future reference.

 
Written By
Tutorial by: Jeremy LeSarge (AKA Ray)

I am the owner and administrator of DialMe.com. I write Tutorials for Boonex Dolphin as well as tips and resources surrounding website programming and development. I enjoy working with WordPress, SEO, and Web Hosting / Servers. I also maintain a WordPress Blog here on this site where you will find a variety of technology and webmaster resources.

Actions
Sponsored Links
Recommend