changed git call from https to git readonly
[atutor.git] / mods / wiki / plugins / feature / anacron.php
1 <?php
2 /*
3    Load this script to make use of the tools/cron.d/ utilities without
4    having to set up a real cron(8) daemon rule. But please use this
5    only if you have no other choice, as it could slow down your Web
6    server. This snippet activates the run-parts in PHP shutdown mode
7    around every second hour (depends on how many users/bots walk over
8    your server).
9    You must run the cron.d/ run-parts script _ONCE_ before this works,
10    because this does not create the required+special database entry.
11 */
12
13 define("EWIKI_ANACRON_INTERLEAVE", 2*3600);   // in seconds
14 define("EWIKI_ANACRON_ID", "etc/anacron/last-run");   // a _SYSTEM entry
15
16
17 #-- checks elapsed timeframe, and installs _runparts for shutdown action
18 $ewiki_plugins["init"][] = "ewiki_anacron_checktime";
19 function ewiki_anacron_checktime() {
20    global $ewiki_plugins;
21    if ( ($d = ewiki_db::GET(EWIKI_ANACRON_ID))
22     and ($d = unserialize($d["content"]))
23     and ($d["last"] >= UNIX_MILLENNIUM)
24     and (time() >= $d["last"] + EWIKI_ANACRON_INTERLEAVE) )
25    {
26       register_shutdown_function("ewiki_anacron_runparts");
27    }
28 }
29
30
31 #-- every two hours: starts run-parts
32 function ewiki_anacron_runparts() {
33
34    // clean up env, because we've been triggered by someone innocent
35    $_SERVER["REMOTE_ADDR"] = "0.0.0.0";
36    $_SERVER["REMOTE_PORT"] = "-";
37    $ewiki_author = "ewiki_anacron_runparts";
38
39    // only works for more or less standard installations
40    include(EWIKI_BASE_DIR."/tools/cron.d/run-parts.php");
41 }
42
43 ?>