]> git.mxchange.org Git - friendica.git/blob - include/cronhooks.php
New process table for a better detection of running workers
[friendica.git] / include / cronhooks.php
1 <?php
2
3 require_once("boot.php");
4
5
6 function cronhooks_run(&$argv, &$argc){
7         global $a, $db;
8
9         if(is_null($a)) {
10                 $a = new App;
11         }
12
13         if(is_null($db)) {
14                 @include(".htconfig.php");
15                 require_once("include/dba.php");
16                 $db = new dba($db_host, $db_user, $db_pass, $db_data);
17                 unset($db_host, $db_user, $db_pass, $db_data);
18         };
19
20         $a->start_process();
21
22         require_once('include/session.php');
23         require_once('include/datetime.php');
24
25         load_config('config');
26         load_config('system');
27
28         // Don't check this stuff if the function is called by the poller
29         if (App::callstack() != "poller_run") {
30                 if (App::maxload_reached())
31                         return;
32                 if (App::is_already_running('cronhooks', 'include/cronhooks.php', 1140))
33                         return;
34         }
35
36         load_hooks();
37
38         if (($argc == 2) AND is_array($a->hooks) AND array_key_exists("cron", $a->hooks)) {
39                 foreach ($a->hooks["cron"] as $hook)
40                         if ($hook[1] == $argv[1]) {
41                                 logger("Calling cron hook '".$hook[1]."'", LOGGER_DEBUG);
42                                 call_single_hook($a, $name, $hook, $data);
43                         }
44                 return;
45         }
46
47         $last = get_config('system','last_cronhook');
48
49         $poll_interval = intval(get_config('system','cronhook_interval'));
50         if(! $poll_interval)
51                 $poll_interval = 9;
52
53         if($last) {
54                 $next = $last + ($poll_interval * 60);
55                 if($next > time()) {
56                         logger('cronhook intervall not reached');
57                         return;
58                 }
59         }
60
61         $a->set_baseurl(get_config('system','url'));
62
63         logger('cronhooks: start');
64
65         $d = datetime_convert();
66
67         if (get_config("system", "worker") AND is_array($a->hooks) AND array_key_exists("cron", $a->hooks)) {
68                 foreach ($a->hooks["cron"] as $hook) {
69                         logger("Calling cronhooks for '".$hook[1]."'", LOGGER_DEBUG);
70                         proc_run(PRIORITY_MEDIUM, "include/cronhooks.php", $hook[1]);
71                 }
72         } else
73                 call_hooks('cron', $d);
74
75         logger('cronhooks: end');
76
77         set_config('system','last_cronhook', time());
78
79         return;
80 }
81
82 if (array_search(__file__,get_included_files())===0){
83         cronhooks_run($_SERVER["argv"],$_SERVER["argc"]);
84         killme();
85 }