}
}
+ $last = get_config('system','last_cron');
+
+ $poll_interval = intval(get_config('system','cron_interval'));
+ if(! $poll_interval)
+ $poll_interval = 10;
+
+ if($last) {
+ $next = $last + ($poll_interval * 60);
+ if($next > time()) {
+ logger('cron intervall not reached');
+ return;
+ }
+ }
+
$lockpath = get_lockpath();
if ($lockpath != '') {
$pidfile = new pidfile($lockpath, 'cron');
logger('cron: start');
+ // run queue delivery process in the background
+
+ proc_run('php',"include/queue.php");
+
+ // run diaspora photo queue process in the background
+
+ proc_run('php',"include/dsprphotoq.php");
+
+ // run the process to discover global contacts in the background
+
+ proc_run('php',"include/discover_poco.php");
+
+ // run the process to update locally stored global contacts in the background
+
+ proc_run('php',"include/discover_poco.php", "checkcontact");
+
// expire any expired accounts
q("UPDATE user SET `account_expired` = 1 where `account_expired` = 0
logger('cron: end');
+ set_config('system','last_cron', time());
+
return;
}
$r = q("SELECT `url`, `nurl`, `addr`, `alias`, `batch`, `notify`, `poll`, `poco`, `network` FROM `contact` WHERE `id` = %d", intval($id));
if (!$r)
- return;
+ return false;
$ret = probe_url($r[0]["url"]);
// If probe_url fails the network code will be different
if ($ret["network"] != $r[0]["network"])
- return;
+ return false;
$update = false;
}
if (!$update)
- return;
+ return true;
q("UPDATE `contact` SET `url` = '%s', `nurl` = '%s', `addr` = '%s', `alias` = '%s', `batch` = '%s', `notify` = '%s', `poll` = '%s', `poco` = '%s' WHERE `id` = %d",
dbesc($ret['url']),
dbesc($ret['poco']),
intval($id)
);
+
+ return true;
}
//
);
// Update the contact entry
- if(($contact['network'] === NETWORK_OSTATUS) || ($contact['network'] === NETWORK_DIASPORA) || ($contact['network'] === NETWORK_DFRN))
- update_contact($contact["id"]);
+ if(($contact['network'] === NETWORK_OSTATUS) || ($contact['network'] === NETWORK_DIASPORA) || ($contact['network'] === NETWORK_DFRN)) {
+ if (!poco_reachable($contact['url'])) {
+ logger("Skipping probably dead contact ".$contact['url']);
+ return;
+ }
+
+ if (!update_contact($contact["id"])) {
+ mark_for_death($contact);
+ return;
+ } else
+ unmark_for_death($contact);
+ }
if($contact['network'] === NETWORK_DFRN) {
unset($db_host, $db_user, $db_pass, $db_data);
};
- // run queue delivery process in the background
-
- proc_run('php',"include/queue.php");
-
- // run diaspora photo queue process in the background
-
- proc_run('php',"include/dsprphotoq.php");
-
- // run the process to discover global contacts in the background
-
- proc_run('php',"include/discover_poco.php");
-
- // run the process to update locally stored global contacts in the background
-
- proc_run('php',"include/discover_poco.php", "checkcontact");
-
- // When everything else is done ...
+ // Run the cron job that calls all other jobs
proc_run("php","include/cron.php");
// Cleaning killed processes
if (function_exists($funcname)) {
logger("Process ".getmypid().": ".$funcname." ".$r[0]["parameter"]);
$funcname($argv, $argc);
- //sleep(10);
+
logger("Process ".getmypid().": ".$funcname." - done");
q("DELETE FROM `workerqueue` WHERE `id` = %d", intval($r[0]["id"]));
require_once('include/items.php');
require_once('include/bbcode.php');
require_once('include/pidfile.php');
+ require_once('include/socgraph.php');
load_config('config');
load_config('system');
else {
// For the first 12 hours we'll try to deliver every 15 minutes
- // After that, we'll only attempt delivery once per hour.
+ // After that, we'll only attempt delivery once per hour.
$r = q("SELECT `id` FROM `queue` WHERE (( `created` > UTC_TIMESTAMP() - INTERVAL 12 HOUR && `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE ) OR ( `last` < UTC_TIMESTAMP() - INTERVAL 1 HOUR ))");
}
foreach($r as $q_item) {
- // queue_predeliver hooks may have changed the queue db details,
+ // queue_predeliver hooks may have changed the queue db details,
// so check again if this entry still needs processing
if($queue_id) {
continue;
}
if(in_array($c[0]['notify'],$deadguys)) {
- logger('queue: skipping known dead url: ' . $c[0]['notify']);
- update_queue_time($q_item['id']);
- continue;
+ logger('queue: skipping known dead url: ' . $c[0]['notify']);
+ update_queue_time($q_item['id']);
+ continue;
+ }
+
+ if (!poco_reachable($c[0]['url'])) {
+ logger('queue: skipping probably dead url: ' . $c[0]['url']);
+ update_queue_time($q_item['id']);
+ continue;
}
- $u = q("SELECT `user`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`
+ $u = q("SELECT `user`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`
FROM `user` WHERE `uid` = %d LIMIT 1",
intval($c[0]['uid'])
);
call_hooks('queue_deliver', $a, $params);
if($params['result'])
- remove_queue_item($q_item['id']);
+ remove_queue_item($q_item['id']);
else
- update_queue_time($q_item['id']);
+ update_queue_time($q_item['id']);
break;
}
if ((($network == "") OR ($name == "") OR ($profile_photo == "") OR ($server_url == "") OR $alternate)
- AND poco_reachable($profile_url, $server_url, $network, true)) {
+ AND poco_reachable($profile_url, $server_url, $network, false)) {
$data = probe_url($profile_url);
$orig_profile = $profile_url;
if ($r)
foreach ($r AS $server) {
- if (!poco_check_server($server["url"], $server["network"]))
+ if (!poco_check_server($server["url"], $server["network"])) {
+ // The server is not reachable? Okay, then we will try it later
+ q("UPDATE `gserver` SET `last_poco_query` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc($server["nurl"]));
continue;
+ }
// Fetch all users from the other server
$url = $server["poco"]."/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,generation";
q("UPDATE `gserver` SET `last_poco_query` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc($server["nurl"]));
if (!$complete AND (--$no_of_queries == 0))
break;
- // If the server hadn't replied correctly, then force a sanity check
- } elseif (!poco_check_server($server["url"], $server["network"], true))
- q("UPDATE `gserver` SET `last_poco_query` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc($server["nurl"]));
+ } else {
+ // If the server hadn't replied correctly, then force a sanity check
+ poco_check_server($server["url"], $server["network"], true);
+ // If we couldn't reach the server, we will try it some time later
+ q("UPDATE `gserver` SET `last_poco_query` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc($server["nurl"]));
+ }
}
}