]> git.mxchange.org Git - friendica.git/blob - include/cronhooks.php
3a09da48ceb3a16dba777731ea2e3e72efb058ea
[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         require_once('include/session.php');
21         require_once('include/datetime.php');
22         require_once('include/pidfile.php');
23
24         load_config('config');
25         load_config('system');
26
27         $maxsysload = intval(get_config('system','maxloadavg'));
28         if($maxsysload < 1)
29                 $maxsysload = 50;
30         if(function_exists('sys_getloadavg')) {
31                 $load = sys_getloadavg();
32                 if(intval($load[0]) > $maxsysload) {
33                         logger('system: load ' . $load . ' too high. Poller deferred to next scheduled run.');
34                         return;
35                 }
36         }
37
38         $lockpath = get_lockpath();
39         if ($lockpath != '') {
40                 $pidfile = new pidfile($lockpath, 'cronhooks');
41                 if($pidfile->is_already_running()) {
42                         logger("cronhooks: Already running");
43                         if ($pidfile->running_time() > 19*60) {
44                                 $pidfile->kill();
45                                 logger("cronhooks: killed stale process");
46                                 // Calling a new instance
47                                 proc_run('php','include/cronhooks.php');
48                         }
49                         exit;
50                 }
51         }
52
53         $a->set_baseurl(get_config('system','url'));
54
55         load_hooks();
56
57         logger('cronhooks: start');
58
59         $d = datetime_convert();
60
61         call_hooks('cron', $d);
62
63         logger('cronhooks: end');
64
65         return;
66 }
67
68 if (array_search(__file__,get_included_files())===0){
69   cronhooks_run($_SERVER["argv"],$_SERVER["argc"]);
70   killme();
71 }