]> git.mxchange.org Git - friendica.git/blob - include/discover_poco.php
Query other servers periodically for their known contacts
[friendica.git] / include / discover_poco.php
1 <?php
2
3 require_once("boot.php");
4 require_once("include/socgraph.php");
5
6
7 function discover_poco_run(&$argv, &$argc){
8         global $a, $db;
9
10         if(is_null($a)) {
11                 $a = new App;
12         }
13
14         if(is_null($db)) {
15             @include(".htconfig.php");
16         require_once("include/dba.php");
17             $db = new dba($db_host, $db_user, $db_pass, $db_data);
18         unset($db_host, $db_user, $db_pass, $db_data);
19         };
20
21         require_once('include/session.php');
22         require_once('include/datetime.php');
23         require_once('include/pidfile.php');
24
25         load_config('config');
26         load_config('system');
27
28         $maxsysload = intval(get_config('system','maxloadavg'));
29         if($maxsysload < 1)
30                 $maxsysload = 50;
31         if(function_exists('sys_getloadavg')) {
32                 $load = sys_getloadavg();
33                 if(intval($load[0]) > $maxsysload) {
34                         logger('system: load ' . $load[0] . ' too high. discover_poco deferred to next scheduled run.');
35                         return;
36                 }
37         }
38
39         $lockpath = get_lockpath();
40         if ($lockpath != '') {
41                 $pidfile = new pidfile($lockpath, 'discover_poco');
42                 if($pidfile->is_already_running()) {
43                         logger("discover_poco: Already running");
44                         if ($pidfile->running_time() > 19*60) {
45                                 $pidfile->kill();
46                                 logger("discover_poco: killed stale process");
47                                 // Calling a new instance
48                                 proc_run('php','include/discover_poco.php');
49                         }
50                         exit;
51                 }
52         }
53
54         $a->set_baseurl(get_config('system','url'));
55
56         load_hooks();
57
58         logger('start');
59
60         if (get_config('system','poco_discovery'))
61                 poco_discover();
62
63         logger('end');
64
65         return;
66 }
67
68 if (array_search(__file__,get_included_files())===0){
69   discover_poco_run($_SERVER["argv"],$_SERVER["argc"]);
70   killme();
71 }