]> git.mxchange.org Git - friendica-addons.git/blob - twitter/twitter_sync.php
Merge remote-tracking branch 'refs/remotes/friendica/master'
[friendica-addons.git] / twitter / twitter_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 twitter_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/twitter/twitter.php");
31         require_once("include/pidfile.php");
32
33         $maxsysload = intval(get_config('system','maxloadavg'));
34         if ($maxsysload < 1) {
35                 $maxsysload = 50;
36         }
37         if (function_exists('sys_getloadavg')) {
38                 $load = sys_getloadavg();
39                 if (intval($load[0]) > $maxsysload) {
40                         logger('system: load ' . $load[0] . ' too high. Twitter sync deferred to next scheduled run.');
41                         return;
42                 }
43         }
44
45         if ($argc < 3) {
46                 return;
47         }
48
49         $mode = intval($argv[1]);
50         $uid = intval($argv[2]);
51
52         // This is deprecated with the worker
53         if (function_exists("get_lockpath")) {
54                 $lockpath = get_lockpath();
55                 if ($lockpath != '') {
56                         $pidfile = new pidfile($lockpath, 'twitter_sync-'.$mode.'-'.$uid);
57                         if ($pidfile->is_already_running()) {
58                                 logger("Already running");
59                                 if ($pidfile->running_time() > 9*60) {
60                                         $pidfile->kill();
61                                         logger("killed stale process");
62                                         // Calling a new instance
63                                         proc_run('php','addon/twitter/twitter_sync.php', $mode, $uid);
64                                 }
65                                 exit;
66                         }
67                 }
68         }
69
70         if ($mode == 1) {
71                 twitter_fetchtimeline($a, $uid);
72         } elseif ($mode == 2) {
73                 twitter_fetchhometimeline($a, $uid);
74         }
75 }
76
77 if (array_search(__file__,get_included_files())===0){
78         twitter_sync_run($_SERVER["argv"],$_SERVER["argc"]);
79         killme();
80 }
81 ?>