-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnextupdate.php
30 lines (24 loc) · 968 Bytes
/
nextupdate.php
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
<?php
/**
* Returns number of milli-seconds until next update in JSON format
* Used by Javascript code to show time to next update clock
* Required because server and client times are not always in sync
*/
// how many minutes between server updates
$cronInterval = 15; // 15 mins
// how long to wait for server updates to complete (milliseconds)
$loadDelay = 15000; // 15 secs
// split time into segments based on interval, then find the next
// segment and calcuate the time to next update
$now = getdate();
$currentTime = $now['minutes']+$now['seconds']/60.0;
$segment = (int) ($currentTime / $cronInterval);
$nextsegment = ($segment+1)*$cronInterval;
// add $loadDelay to give server time to fetch data
$timeToUpdate = ($nextsegment - $currentTime) * 60 * 1000 + $loadDelay;
// prevent caching
header("Cache-Control: max-age=0, no-cache, no-store, must-revalidate");
header("Pragma: no-cache");
header("Expires: -1");
print json_encode($timeToUpdate);
?>