]> git.mxchange.org Git - friendica-addons.git/blob - pumpio/pumpio_sync.php
Deprecated parts removed
[friendica-addons.git] / pumpio / pumpio_sync.php
1 <?php
2 if (!file_exists("boot.php") AND (sizeof($_SERVER["argv"]) != 0)) {
3         $directory = dirname($_SERVER["argv"][0]);
4
5         if (substr($directory, 0, 1) != "/")
6                 $directory = $_SERVER["PWD"]."/".$directory;
7
8         $directory = realpath($directory."/..");
9
10         chdir($directory);
11 }
12
13 require_once("boot.php");
14
15
16 function pumpio_sync_run(&$argv, &$argc){
17         global $a, $db;
18
19         if(is_null($a)) {
20                 $a = new App;
21         }
22
23         if(is_null($db)) {
24                 @include(".htconfig.php");
25                 require_once("include/dba.php");
26                 $db = new dba($db_host, $db_user, $db_pass, $db_data);
27                 unset($db_host, $db_user, $db_pass, $db_data);
28         };
29
30         require_once("addon/pumpio/pumpio.php");
31         require_once("include/pidfile.php");
32
33         $maxsysload = intval(get_config('system','maxloadavg'));
34         if($maxsysload < 1)
35                 $maxsysload = 50;
36         if(function_exists('sys_getloadavg')) {
37                 $load = sys_getloadavg();
38                 if(intval($load[0]) > $maxsysload) {
39                         logger('system: load ' . $load[0] . ' too high. Pumpio sync deferred to next scheduled run.');
40                         return;
41                 }
42         }
43
44         // This is deprecated with the worker
45         if (function_exists("get_lockpath")) {
46                 $lockpath = get_lockpath();
47                 if ($lockpath != '') {
48                         $pidfile = new pidfile($lockpath, 'pumpio_sync');
49                         if($pidfile->is_already_running()) {
50                                 logger("Already running");
51                                 if ($pidfile->running_time() > 9*60) {
52                                         $pidfile->kill();
53                                         logger("killed stale process");
54                                         // Calling a new instance
55                                         proc_run('php','addon/pumpio/pumpio_sync.php');
56                                 }
57                                 exit;
58                         }
59                 }
60         }
61         pumpio_sync($a);
62 }
63
64 if (array_search(__file__,get_included_files())===0){
65         pumpio_sync_run($_SERVER["argv"],$_SERVER["argc"]);
66         killme();
67 }
68 ?>