Set "last_failure" on connection timeout when checking server

This commit is contained in:
Michael 2017-05-05 20:51:45 +00:00
parent b9d64be59f
commit 9ab0a9299e

View file

@ -1008,6 +1008,7 @@ function poco_check_server($server_url, $network = "", $force = false) {
if (dbm::is_result($servers) AND ($orig_server_url == $server_url) AND if (dbm::is_result($servers) AND ($orig_server_url == $server_url) AND
($serverret['errno'] == CURLE_OPERATION_TIMEDOUT)) { ($serverret['errno'] == CURLE_OPERATION_TIMEDOUT)) {
logger("Connection to server ".$server_url." timed out.", LOGGER_DEBUG); logger("Connection to server ".$server_url." timed out.", LOGGER_DEBUG);
dba::p("UPDATE `gserver` SET `last_failure` = ? WHERE `nurl` = ?", datetime_convert(), normalise_link($server_url));
return false; return false;
} }
@ -1022,6 +1023,7 @@ function poco_check_server($server_url, $network = "", $force = false) {
// Quit if there is a timeout // Quit if there is a timeout
if ($serverret['errno'] == CURLE_OPERATION_TIMEDOUT) { if ($serverret['errno'] == CURLE_OPERATION_TIMEDOUT) {
logger("Connection to server ".$server_url." timed out.", LOGGER_DEBUG); logger("Connection to server ".$server_url." timed out.", LOGGER_DEBUG);
dba::p("UPDATE `gserver` SET `last_failure` = ? WHERE `nurl` = ?", datetime_convert(), normalise_link($server_url));
return false; return false;
} }
@ -1031,12 +1033,10 @@ function poco_check_server($server_url, $network = "", $force = false) {
if (!$serverret["success"] OR ($serverret["body"] == "") OR (sizeof($xmlobj) == 0) OR !is_object($xmlobj)) { if (!$serverret["success"] OR ($serverret["body"] == "") OR (sizeof($xmlobj) == 0) OR !is_object($xmlobj)) {
// Workaround for bad configured servers (known nginx problem) // Workaround for bad configured servers (known nginx problem)
if (!in_array($serverret["debug"]["http_code"], array("403", "404"))) { if (!in_array($serverret["debug"]["http_code"], array("403", "404"))) {
$last_failure = datetime_convert();
$failure = true; $failure = true;
} }
$possible_failure = true; $possible_failure = true;
} elseif ($network == NETWORK_DIASPORA) }
$last_contact = datetime_convert();
// If the server has no possible failure we reset the cached data // If the server has no possible failure we reset the cached data
if (!$possible_failure) { if (!$possible_failure) {
@ -1054,8 +1054,6 @@ function poco_check_server($server_url, $network = "", $force = false) {
$data = json_decode($serverret["body"]); $data = json_decode($serverret["body"]);
if (isset($data->totalResults)) { if (isset($data->totalResults)) {
$poco = $server_url."/poco"; $poco = $server_url."/poco";
$last_contact = datetime_convert();
$server = poco_detect_poco_data($data); $server = poco_detect_poco_data($data);
if ($server) { if ($server) {
$platform = $server['platform']; $platform = $server['platform'];
@ -1072,7 +1070,6 @@ function poco_check_server($server_url, $network = "", $force = false) {
$serverret = z_fetch_url($server_url); $serverret = z_fetch_url($server_url);
if (!$serverret["success"] OR ($serverret["body"] == "")) { if (!$serverret["success"] OR ($serverret["body"] == "")) {
$last_failure = datetime_convert();
$failure = true; $failure = true;
} else { } else {
$server = poco_detect_server_type($serverret["body"]); $server = poco_detect_server_type($serverret["body"]);
@ -1081,7 +1078,6 @@ function poco_check_server($server_url, $network = "", $force = false) {
$network = $server['network']; $network = $server['network'];
$version = $server['version']; $version = $server['version'];
$site_name = $server['site_name']; $site_name = $server['site_name'];
$last_contact = datetime_convert();
} }
$lines = explode("\n",$serverret["header"]); $lines = explode("\n",$serverret["header"]);
@ -1095,15 +1091,11 @@ function poco_check_server($server_url, $network = "", $force = false) {
$network = NETWORK_DIASPORA; $network = NETWORK_DIASPORA;
$versionparts = explode("-", $version); $versionparts = explode("-", $version);
$version = $versionparts[0]; $version = $versionparts[0];
$last_contact = datetime_convert();
} }
if(stristr($line,'Server: Mastodon')) { if(stristr($line,'Server: Mastodon')) {
$platform = "Mastodon"; $platform = "Mastodon";
$network = NETWORK_OSTATUS; $network = NETWORK_OSTATUS;
// Mastodon doesn't reveal version numbers
$version = "";
$last_contact = datetime_convert();
} }
} }
} }
@ -1122,7 +1114,6 @@ function poco_check_server($server_url, $network = "", $force = false) {
$version = str_replace(chr(239).chr(187).chr(191), "", $serverret["body"]); $version = str_replace(chr(239).chr(187).chr(191), "", $serverret["body"]);
$version = trim($version, '"'); $version = trim($version, '"');
$network = NETWORK_OSTATUS; $network = NETWORK_OSTATUS;
$last_contact = datetime_convert();
} }
// Test for GNU Social // Test for GNU Social
@ -1134,7 +1125,6 @@ function poco_check_server($server_url, $network = "", $force = false) {
$version = str_replace(chr(239).chr(187).chr(191), "", $serverret["body"]); $version = str_replace(chr(239).chr(187).chr(191), "", $serverret["body"]);
$version = trim($version, '"'); $version = trim($version, '"');
$network = NETWORK_OSTATUS; $network = NETWORK_OSTATUS;
$last_contact = datetime_convert();
} }
// Test for Mastodon // Test for Mastodon
@ -1147,7 +1137,6 @@ function poco_check_server($server_url, $network = "", $force = false) {
$site_name = $data->title; $site_name = $data->title;
$info = $data->description; $info = $data->description;
$network = NETWORK_OSTATUS; $network = NETWORK_OSTATUS;
$last_contact = datetime_convert();
} }
} }
} }
@ -1158,8 +1147,6 @@ function poco_check_server($server_url, $network = "", $force = false) {
if ($serverret["success"]) { if ($serverret["success"]) {
$data = json_decode($serverret["body"]); $data = json_decode($serverret["body"]);
if (isset($data->site->server)) { if (isset($data->site->server)) {
$last_contact = datetime_convert();
if (isset($data->site->platform)) { if (isset($data->site->platform)) {
$platform = $data->site->platform->PLATFORM_NAME; $platform = $data->site->platform->PLATFORM_NAME;
$version = $data->site->platform->STD_VERSION; $version = $data->site->platform->STD_VERSION;
@ -1206,7 +1193,6 @@ function poco_check_server($server_url, $network = "", $force = false) {
} }
} }
// Query statistics.json. Optional package for Diaspora, Friendica and Redmatrix // Query statistics.json. Optional package for Diaspora, Friendica and Redmatrix
if (!$failure) { if (!$failure) {
$serverret = z_fetch_url($server_url."/statistics.json"); $serverret = z_fetch_url($server_url."/statistics.json");
@ -1234,9 +1220,6 @@ function poco_check_server($server_url, $network = "", $force = false) {
} else { } else {
$register_policy = REGISTER_CLOSED; $register_policy = REGISTER_CLOSED;
} }
if (isset($data->version))
$last_contact = datetime_convert();
} }
} }
@ -1261,8 +1244,6 @@ function poco_check_server($server_url, $network = "", $force = false) {
if (isset($server['site_name'])) { if (isset($server['site_name'])) {
$site_name = $server['site_name']; $site_name = $server['site_name'];
} }
$last_contact = datetime_convert();
} }
} }
@ -1278,7 +1259,6 @@ function poco_check_server($server_url, $network = "", $force = false) {
$data = json_decode($serverret["body"]); $data = json_decode($serverret["body"]);
if (isset($data->version)) { if (isset($data->version)) {
$last_contact = datetime_convert();
$network = NETWORK_DFRN; $network = NETWORK_DFRN;
$noscrape = $data->no_scrape_url; $noscrape = $data->no_scrape_url;
@ -1304,13 +1284,14 @@ function poco_check_server($server_url, $network = "", $force = false) {
} }
if ($possible_failure AND !$failure) { if ($possible_failure AND !$failure) {
$last_failure = datetime_convert();
$failure = true; $failure = true;
} }
if ($failure) { if ($failure) {
$last_contact = $orig_last_contact; $last_contact = $orig_last_contact;
$last_failure = datetime_convert();
} else { } else {
$last_contact = datetime_convert();
$last_failure = $orig_last_failure; $last_failure = $orig_last_failure;
} }