#native_company# #native_desc#
#native_cta#

Sets META tag for REFRESH to when page will be updated

By Conan Ford
on August 11, 2000

Version: 0.01

Type: Sample Code (HOWTO)

Category: HTTP

License: GNU Library Public License

Description: If you have a page that is automatically updated on a pre-set interval, this code snippet is for setting the user’s browser to update it on the next interval. Typically people just set the update interval to, say, 500 seconds, but you’d really like it to update when it’s ready. This way, they reload probably right around when it’s done.

If you’re concerned about load balancing issues with lots of users loading a page at once, you could add a random factor as well.

  <?php
      function reloadtime(){
	/* This is for when you have a page that updates automatically on a pre */
	/* defined time, like every 20 minutes for example, and you want the user */
	/* to reload it at the next interval.  Normal practice is to just set */
	/* the refresh time to 20 minutes, but if the next update is in, say, 7 */
	/* minutes, then they're always 13 minutes behind */
	/* */
	/* Put this in the HEAD section of the html document */
	/* */
	/* To set the user's browser to load the page every 20 minutes, at */
	/* 2, 22, 42 minutes after the hour, use interval of 20*60, and extra */
	/* of 2*60.  To have it load at 0,20,40, use interval 20*60, and extra */
	/* of 0 */
	/* [email protected] */

        /* how often the page is updated, in seconds */
        $interval = 20*60;

	/* how often after the page update to have the user reload the page */
        $extra = 2*60;
	
        $currtime=getdate(time());

        $updtime = $interval - ( ($currtime["minutes"]*60 + $currtime["seconds"]
 ) % $interval ) + $extra;
        if ($updtime >= $interval)
                $updtime -= $interval;
        return $updtime;
      }

      $refreshtime = reloadtime();
      print("<META HTTP-EQUIV="Refresh" CONTENT="$refreshtime">n");
   ?>