5 if (!file_exists("boot.php") AND (sizeof($_SERVER["argv"]) != 0)) {
6 $directory = dirname($_SERVER["argv"][0]);
8 if (substr($directory, 0, 1) != "/")
9 $directory = $_SERVER["PWD"]."/".$directory;
11 $directory = realpath($directory."/..");
16 require_once("boot.php");
19 function twitter_sync_run($argv, $argc){
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);
33 require_once("addon/twitter/twitter.php");
34 require_once("include/pidfile.php");
36 $maxsysload = intval(get_config('system','maxloadavg'));
37 if ($maxsysload < 1) {
40 if (function_exists('sys_getloadavg')) {
41 $load = sys_getloadavg();
42 if (intval($load[0]) > $maxsysload) {
43 logger('system: load ' . $load[0] . ' too high. Twitter sync deferred to next scheduled run.');
52 $mode = intval($argv[1]);
53 $uid = intval($argv[2]);
55 // This is deprecated with the worker
56 if (function_exists("get_lockpath")) {
57 $lockpath = get_lockpath();
58 if ($lockpath != '') {
59 $pidfile = new pidfile($lockpath, 'twitter_sync-'.$mode.'-'.$uid);
60 if ($pidfile->is_already_running()) {
61 logger("Already running");
62 if ($pidfile->running_time() > 9*60) {
64 logger("killed stale process");
65 // Calling a new instance
66 proc_run('php','addon/twitter/twitter_sync.php', $mode, $uid);
74 twitter_fetchtimeline($a, $uid);
75 } elseif ($mode == 2) {
76 twitter_fetchhometimeline($a, $uid);
80 if (array_search(__file__,get_included_files())===0){
81 twitter_sync_run($_SERVER["argv"],$_SERVER["argc"]);