Server Time Difference
Previous article Next articleHaving problems with start and end time settings in a CMS Made Simple™ module? A news article is published, but isn't visible at the frontend of the website... You could have problems with the time settings at your website and/or server.
A few useful checks to see if it is a problem you can fix yourself, or you have to contact your webhost...
How to use
1. UNIX timestamp
First check the current Unix timestamp by adding in a page:
2. Check the time zone settings (daylight saving time)
You can test this with a User Defined Tag (UDT).
In the Admin panel go to Extensions >> User Defined Tags and create a new UDT:
UDT: test_server_timezones
echo "PHP time is " . $db->DbTimeStamp(time()) . "<br />";
echo "MySQL time is '" . $db->GetOne('SELECT NOW()') . "'<br />";
To use this test UDT click on the "Run" button in the Admin page. The output will be shown in a pop-up box.
Is the date and time not correct? Adjust the settings in your config.php file in the CMSMS™ website root.
Change the value for your countries time zone (or the time zone where your server is...).
Is your database server on a different machine, it may be necessary to also add:
You still have a time difference issue, there can be a problem at your server. We can test it with two small UDT's.
3. Database Time Difference
Related CMS Made Simple warning:
Testing for time difference in the database (test_db_timedifference)
Detected a difference of at least ... seconds. This may effect the system dramatically.
In the Admin panel go to Extensions >> User Defined Tags and create a new UDT:
UDT: test_db_timedifference
$diff = time() - $db->GetOne('SELECT UNIX_TIMESTAMP()');
echo "DB Time Difference is $diff seconds";
This UDT tests the time difference between the current Unix timestamp and database server time.
To use the test UDT click on the "Run" button in the Admin page. The output will be shown in a pop-up box.
The output should be 0 seconds, in case of another value you need to contact your web host to change the server settings.
4. File System Time Difference
Related CMS Made Simple warning:
Testing for time difference in the file system (test_file_timedifference)
A discrepency in time with the PHP environment was detected. This may cause problems when publishing i.e. news articles.
In the Admin panel go to Extensions >> User Defined Tags and create a new UDT:
UDT: test_file_timedifference
touch($fn);
$diff = time() - filemtime($fn);
echo "File Time Difference is $diff seconds";
This UDT tests the time difference between the current Unix timestamp and file server time.
To use the test UDT click on the "Run" button in the Admin page. The output will be shown in a pop-up box.
The output should be 0 seconds, in case of another value you need to contact your web host to change the server settings.
Comment Form
ReviewManager
ReviewManager
3 Comments
News articles don't publish until 3 hours later. We are in Eastern timezone; server is on west coast, 3 hours behind us.
A test page on my site shows:
(#1 test) Smarty reports the current time is Saturday 18-09-2021 18:01:52 EDT
document.write("Local machine time is: " + localTime + "");
shows
Local machine time is: Sat Sep 18 2021 18:01:52 GMT-0400 (Eastern Daylight Time)
document.write("Server time is: " + date); shows
Server time is: Sat Sep 18 2021 18:01:53 GMT-0400 (Eastern Daylight Time)
All Correct so far.
test_server_timezones shows
PHP time is '2021-09-18 18:05:49'
MySQL time is '2021-09-18 15:05:49'
First one is correct, MySQL is 3 hours off.
But the database is not "on a different machine"--it is on our west coast server, as I understand it.
test_db_timedifference and test_file_timedifference both show 0 seconds.
Is fixing this just as simple as
$config['set_db_timezone'] = 'true';
I already have
$config['timezone'] = 'America/New_York';
This became a problem when our webhost moved us to a new supposedly faster server.
Thanks yet again for an other great post!
CGblog posts where not showing up when I posted them because apparently the MySQL database time (on the same server) was incorrect!
I just added $config['set_db_timezone'] = 'true'; in the config and problem was fixed :)
I would have wasted way more time on this without your article so a couple of coffees are donated ;)
Greetings,
Manuel
In CMSMS v2.2.8 - $config['set_db_timezone'] is Boolean - so that should be either '1' or TRUE as the value (i think).