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