|
Updating a page strictly every minute (PHP, Perl)
 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 HandlingP404 - Perl - Extending Flexibility Using CGIP406 - Perl - More CGI Programs and FacilitiesQ110 - Object Orientation and General technical topics - Programming AlgorithmsW502 - Web and Intranet - HTML Document AnatomyW511 - Web and Intranet - Further Aspects
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 pointersImproving searches - from OR to AND?Painting a masterpiece in PHP
|
2258 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 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).
|
|