
For the
Clock exercise that I mentioned in my last entry, I need to update the page once a minute.
Exactly once a minute. At the
start of the minute.
I'm using client pull, where the browser asks for the next page - so my basic request is:
<meta http-equiv="refresh" content="60; url=/clock/now.php">
but that will neither refresh at the start of the minute, nor be exact - with update times and delays taken into account, a handful of times in each hour will be missed out (I know this - I tried it) as the 60 seconds starts from the time the new page is received, not from the previous page.
So I have adjusted the time as follows:
$togo = 61 - date("s");
if ($togo < 15) $togo = 15;
to calculate how long before we trigger - it's going to trigger 1 second into the next minute, and will be selfcorrecting to allow for page transmission times. The business with the "15" is to ensure that initial pages display for at least 15 seconds, even if - by rights - they should be refreshed quicker. That will help avoid an irritating refresh. And the client pull instruction becomes:
<meta http-equiv="refresh" content="<?= $togo ?>; url=/clock/now.php">
The example above is "Client Pull". There's also a complete "Server Push" example, written in Perl, using the same algorithm available for you
here (written 2007-05-14 14:11:39)
Associated topics are indexed under
H112 - PHP - Further Web Page and Network Handling [1549] http, https and ajp - comparison and choice - (2008-02-22)
[1518] Downloading data for use in Excel (from PHP / MySQL) - (2008-01-25)
[1515] Keeping staff up to date on hotel room status - (2008-01-22)
[1505] Script to present commonly used images - PHP - (2008-01-13)
[1496] PHP / Web 2 logging - (2008-01-06)
[1495] Single login and single threaded models - Java and PHP - (2008-01-04)
[1485] Copyright and theft of images, bandwidth and members. - (2007-12-26)
[1379] Simple page password protection - PHP - (2007-10-04)
[1355] .php or .html extension? Morally Static Pages - (2007-09-17)
[1210] PHP header() function - uses and new restrictions - (2007-05-30)
[1183] Improving searches - from OR to AND? - (2007-05-11)
[1114] PHP Image upload script - (2007-03-21)
[1009] Passing GET parameters through Apache mod_rewrite - (2006-12-27)
[936] Global, Superglobal, Session variables - scope and persistance in PHP - (2006-11-21)
[904] Of course I'll tell you by email - (2006-10-25)
[847] Image maps for navigation - a straightforward example - (2006-08-28)
[789] Hot answers in PHP - (2006-07-02)
[767] Finding the language preference of a web site visitor - (2006-06-18)
[732] Where is a web site visitor browsing from - (2006-05-24)
[675] Adding PHP tags to an old cgi program - (2006-04-08)
[603] PHP - setting sort order with an associative array - (2006-02-13)
[565] Using PHP to output images, XML, Style sheets, etc - (2006-01-15)
[542] Morning image, afternoon image - (2005-12-26)
[537] Daily Image Santafied - (2005-12-22)
[484] Setting the file name for a downloaded document - (2005-11-03)
[451] Accessing a page via POST from within a PHP script - (2005-09-26)
[443] Server side scripting of styles to suit the browser - (2005-09-12)
[425] Caching an XML feed - (2005-08-26)
[410] Reading a news or blog feed (RSS) in your PHP page - (2005-08-12)
[376] What brings people to my web site? - (2005-07-13)
[372] Time calculation in PHP - (2005-07-08)
[356] Sudoku helper or sudoku cheat - (2005-06-23)
[345] Spotting a denial of service attack - (2005-06-12)
[314] What language is this written in? - (2005-05-17)
[220] When to use Frames - (2005-02-19)
P404 - Perl - Extending Flexibility Using CGI [1365] Korn Shell scripts on the web - (2007-09-25)
[641] Simple but rugged form handling demo - (2006-03-10)
[590] Danny and Donna are getting married - (2006-02-03)
[426] Robust checking of data entered by users - (2005-08-27)
P406 - Perl - More CGI Programs and Facilities [2321] Uploading and Downloading files - changing names (Perl and PHP) - (2009-08-04)
Q110 - Object Orientation and General technical topics - Programming Algorithms [2617] Comparing floating point numbers - a word of caution and a solution - (2010-02-01)
[2586] And and Or illustrated by locks - (2010-01-17)
[2509] A life lesson from the accuracy of numbers in Excel and Lua - (2009-11-21)
[2259] Grouping rows for a summary report - MySQL and PHP - (2009-06-27)
[2189] Matching disparate referencing systems (MediaWiki, PHP, also Tcl) - (2009-05-19)
[1949] Nuclear Physics comes to our web site - (2008-12-17)
[1840] Validating Credit Card Numbers - (2008-10-14)
[1391] Ordnance Survey Grid Reference to Latitude / Longitude - (2007-10-14)
[1157] Speed Networking - a great evening and how we arranged it - (2007-04-21)
[642] How similar are two words - (2006-03-11)
[227] Bellringing and Programming and Objects and Perl - (2005-02-25)
[202] Searching for numbers - (2005-02-04)
W502 - Web and Intranet - HTML Document Anatomy [2246] What difference does using the XHTML standard really make? - (2009-06-18)
[1811] Alternative URLs using % symbol encoding - (2008-09-27)
[1463] All the special characters in HTML ... - (2007-12-07)
[1431] Getting the community on line - some basics - (2007-11-13)
[1160] HTML - example of a simple web page - (2007-04-24)
[993] Positioning with Cascading Style Sheets - (2006-12-16)
[857] Strikingly busy - (2006-09-06)
W511 - Web and Intranet - Further Aspects [1970] Plagarism - who is copying my pages? - (2009-01-02)
[1001] .pdf files - upload via PHP, store in MySQL, retrieve - (2006-12-19)
[876] Making pages clearer - easy Disability Discrimination Act Compliance - (2006-09-23)
[528] Getting favicon to work - avoiding common pitfalls - (2005-12-14)
Some other Articles
Smart English Output - via PHP and Perl ? : operatorSave the Forum - A regular clean sweepMeet, greet and welcomeWhat shape is your shake?Updating a page strictly every minute (PHP, Perl)Two new pages / sitesThemes for the web siteFinding resources - some pointersPainting a masterpiece in PHP