Main Content
Updating a page strictly every minute (PHP, Perl) Archive - Originally posted on "The Horse's Mouth" - 2007-05-14 14:11:39 - Graham Ellis
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
Some other articles
W511 - Further Aspects Plagarism - who is copying my pages? This article .pdf files - upload via PHP, store in MySQL, retrieve Making pages clearer - easy Disability Discrimination Act Compliance Getting favicon to work - avoiding common pitfalls W502 - HTML Document Anatomy The VERY basics of a web page ... and web site How big is a web page these days? Does the size of your pages matter? Tags used in writing this blog Redirecting to your main domain for correct security keys What difference does using the XHTML standard really make? Alternative URLs using % symbol encoding All the special characters in HTML ... Getting the community on line - some basics This article HTML - example of a simple web page Positioning with Cascading Style Sheets Strikingly busy Q110 - Programming Algorithms Some gems from an introduction to Python Identifying the first and last records in a sequence Testing new algorithms in PHP A good example of recursion - a real use in Python Finding sum, minimum, maximum and average in Python (and Ruby) Selecting RECENT and POPULAR news and trends for your web site users Learning to program - what are algorithms and design patterns? Finding all the unique lines in a file, using Python or Perl Finding the total, average, minimum and maximum in a program Why would you want to use a Perl hash? AND and OR operators - what is the difference between logical and bitwise varieties? How many toilet rolls - hotel inventory and useage Finding elements common to many lists / arrays Least Common Ancestor - what is it, and a Least Common Ancestor algorithm implemented in Perl Arrays v Lists - what is the difference, why use one or the other Lots of way of converting 3 letter month abbreviations to numbers Sorting people by their names Comparing floating point numbers - a word of caution and a solution And and Or illustrated by locks A life lesson from the accuracy of numbers in Excel and Lua Grouping rows for a summary report - MySQL and PHP Matching disparate referencing systems (MediaWiki, PHP, also Tcl) Nuclear Physics comes to our web site Validating Credit Card Numbers Ordnance Survey Grid Reference to Latitude / Longitude This article Speed Networking - a great evening and how we arranged it How similar are two words Bellringing and Programming and Objects and Perl Searching for numbers P406 - More CGI Programs and Facilities Uploading and Downloading files - changing names (Perl and PHP) This article Passing GET parameters through Apache mod_rewrite Simple but rugged form handling demo P404 - Extending Flexibility Using CGI Korn Shell scripts on the web This article Simple but rugged form handling demo Danny and Donna are getting married Robust checking of data entered by users H112 - Further Web Page and Network Handling Moving from mysql to mysqli - simple worked example Passing variable between PHP pages - hidden fields, cookies and sessions Multiple page web applications - maintaining state - PHP Telling which ServerAlias your visitor used - useful during merging domains Easy session example in PHP - keeping each customers data apart 3 digit HTTP status codes - what are they, which are most common, which should be a concern? Sending out an email containing HTML from within a PHP page Downloading a report from the web for further local analysis Uploading a document or image to its own URL via a browser How to build a test harness into your PHP Shipping a test harness with your class in PHP http, https and ajp - comparison and choice Downloading data for use in Excel (from PHP / MySQL) Keeping staff up to date on hotel room status Script to present commonly used images - PHP PHP / Web 2 logging Single login and single threaded models - Java and PHP Copyright and theft of images, bandwidth and members. Simple page password protection - PHP .php or .html extension? Morally Static Pages PHP header() function - uses and new restrictions This article Improving searches - from OR to AND? PHP Image upload script Passing GET parameters through Apache mod_rewrite Global, Superglobal, Session variables - scope and persistance in PHP Of course I'll tell you by email Image maps for navigation - a straightforward example Hot answers in PHP Finding the language preference of a web site visitor Adding PHP tags to an old cgi program PHP - setting sort order with an associative array Using PHP to output images, XML, Style sheets, etc Morning image, afternoon image Daily Image Santafied Setting the file name for a downloaded document Accessing a page via POST from within a PHP script Server side scripting of styles to suit the browser Caching an XML feed Reading a news or blog feed (RSS) in your PHP page What brings people to my web site? Time calculation in PHP Sudoku helper or sudoku cheat Spotting a denial of service attack What language is this written in? When to use Frames