Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
Python and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Lua, etc
 
On time

Do we need to be on time? Well ... if I go to the station at 07:20 - that's a minute late for the 07:19 - there's a good chance that I'll have missed the train and have to make alternative arrangements to get where I need to be. Even a few seconds and "sorry, mate - I've already closed the doors; you'll have to wait for the next one". So something like the Maidenhead station clock (oops - the picture is Helsinki) needs to be on time to the second.

Where financial transaction, bid sites, and some other web sites / actions are concerned, every second - and fraction of a second - matters, and the Network Time Protocol (NTP) exists to take the time on central atomic clocks and share it with other servers, which in turn share it onwards. But there's an awful lot more to that than you might anticipate; to get the time setting as accurate as possible, a conversation back and forth to each server to work out the lag time (time for data to travel) is needed, and indeed it's worth a machine that's being set up checking with several servers, rejecting any which are in spectacular disagreement, and setting itself based on the result. The home page of NTP is [here].

The clock on one of our dedicated servers "drifts". Set it right, and it's a few seconds in error by the end of the day (not a problem), a minute or two by the end of a fortnight (no big issue) and perhaps 10 or 15 minutes out after a couple of months. By the time it's got to that level, messages back and forth between our team are getting mistimed, it looks as if staff are clocking in late, and the synchronization between data on that system and the shared server that we use elsewhere for backup and various other purposes is getting flaky. So we need to reset / adjust every so often.

NTP? Surprisingly, no. We're behind a firewall and have to play with port 123 on that / get it changed if we want to use NTP. NTP has a baffling array of configurations available which are solving a fine accuracy issue which isn't an issue to us. And in any case, we want to reflect the time that's set on the shared server, which may itself be a few seconds adrift from time to time, and not the central atomic clock. So I've put a very short PHP script onto the backup server which does no more than server the current time:

<?php
print(time());
?>


And called that up each day, in a regular (crontab) job on the live system ... the line in my crontab looks something like this:

21 1 * * * /bin/date `/usr/bin/php -r 'echo date("mdHiY.s",file_get_contents("http://backupservername.net/checktime.php"));'`

As technical notes

a) The Crontab job has to run a root to have the authority to set the clock

b) I have (of course) changed the server and file name in my example - simply to avoid encouraging the world to set their time easily from our hosted service by virtue of my publishing this

c) The crontab job should actually run a slightly more complex PHP script that deals with cases of major slippage between the machines, and skip over the synchronization if the remote machine does not respond

We cover crontab on our Introduction to Linux Administration course. Crontab is often used on web servers for regular maintainance tasks, and for periodic logging. We also use it to change the look and feel of the website to different templates for Christmas.

(written 2011-01-23, updated 2011-01-25)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
A164 - Web Application Deployment - Services and Regular Jobs
  [4487] Starting MySQL. ERROR! The server quit without updating PID file - how we fixed it. - (2015-05-06)
  [3792] Managing daemons from a terminal session - (2012-07-01)
  [3791] The Kernel, Shells and Daemons. Greek Gods in computing - (2012-07-01)
  [3011] What are .pid files? - (2010-10-23)
  [2182] What Linux run level am I in? - (2009-05-15)
  [2145] Using the internet to remotely check for power failure at home (PHP) - (2009-04-29)
  [1903] daemons - what is running on my Linux server? - (2008-11-23)
  [1765] Dialects of English and Unix - (2008-08-21)
  [1733] memcached - overview, installation, example of use in PHP - (2008-08-02)
  [1731] Apache httpd, MySQL, PHP - installation procedure - (2008-08-01)
  [1700] FTP server on Fedora Linux - (2008-07-06)
  [1633] Changing a screen saver from a web page (PHP, Perl, OSX) - (2008-05-06)
  [1553] Automatic startup and shutdown of Tomcat - (2008-02-24)
  [1288] Linux run states, shell special commands, and directory structures - (2007-08-03)
  [1028] Linux / Unix - process priority and nice - (2007-01-10)
  [907] Browser -> httpd -> Tomcat -> MySQL. Restarting. - (2006-10-28)
  [544] Repeating tasks with crontab - (2005-12-27)

H305 - PHP - Web server configuration
  [2981] How to set up short and meaningfull alternative URLs - (2010-10-02)
  [2774] PHP - Object Oriented Design in use - (2010-05-21)
  [2773] Dynamically watching your web site via a PHP wrapper - (2010-05-21)
  [2478] How did I do THAT? - (2009-10-26)
  [1938] Predictive Load Balancing - PHP and / or Java - (2008-12-13)
  [1778] Pointing all the web pages in a directory at a database - (2008-08-30)


Back to
Private and Public - and things between
Previous and next
or
Horse's mouth home
Forward to
Setting up arrays in C - fixed size at compile time, or dynamic
Some other Articles
Hotel star ratings - towards a better system of review
Strings in C
Structures v Structure Pointers in C. How, which, why.
Setting up arrays in C - fixed size at compile time, or dynamic
On time
Private and Public - and things between
Wiltshire Rail services - a golden opportunity
Django - separating the HTML from the view / model
Steering our Python courses towards wxPython, SQLite and Django
Django - adding your own views, and then templating your views.
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2019: 404 The Spa • Melksham, Wiltshire • United Kingdom • SN12 6QL
PH: 01225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/3143_On-time.html • PAGE BUILT: Sat May 27 16:49:10 2017 • BUILD SYSTEM: WomanWithCat