X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fsocgraph.php;h=152f713c10a5441978f2d8935ad119da724c3478;hb=1624150db4d0f511d7d119eb645e997bd3f76129;hp=b5fc5aa659e2b139deaac213fc8ea2f8ded7c3e7;hpb=60adf67f1392950b0aba3c589bed65c66058426d;p=friendica.git diff --git a/include/socgraph.php b/include/socgraph.php index b5fc5aa659..152f713c10 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -690,7 +690,7 @@ function poco_check_server($server_url, $network = "", $force = false) { return false; $servers = q("SELECT * FROM `gserver` WHERE `nurl` = '%s'", dbesc(normalise_link($server_url))); - if ($servers) { + if (dbm::is_result($servers)) { if ($servers[0]["created"] <= NULL_DATE) q("UPDATE `gserver` SET `created` = '%s' WHERE `nurl` = '%s'", @@ -732,21 +732,40 @@ function poco_check_server($server_url, $network = "", $force = false) { $orig_last_failure = $last_failure; // Check if the page is accessible via SSL. + $orig_server_url = $server_url; $server_url = str_replace("http://", "https://", $server_url); - $serverret = z_fetch_url($server_url."/.well-known/host-meta"); + + // We set the timeout to 20 seconds since this operation should be done in no time if the server was vital + $serverret = z_fetch_url($server_url."/.well-known/host-meta", false, $redirects, array('timeout' => 20)); + + // Quit if there is a timeout. + // But we want to make sure to only quit if we are mostly sure that this server url fits. + if (dbm::is_result($servers) AND ($orig_server_url == $server_url) AND + ($serverret['errno'] == CURLE_OPERATION_TIMEDOUT)) { + logger("Connection to server ".$server_url." timed out.", LOGGER_DEBUG); + return false; + } // Maybe the page is unencrypted only? $xmlobj = @simplexml_load_string($serverret["body"],'SimpleXMLElement',0, "http://docs.oasis-open.org/ns/xri/xrd-1.0"); if (!$serverret["success"] OR ($serverret["body"] == "") OR (@sizeof($xmlobj) == 0) OR !is_object($xmlobj)) { $server_url = str_replace("https://", "http://", $server_url); - $serverret = z_fetch_url($server_url."/.well-known/host-meta"); + + // We set the timeout to 20 seconds since this operation should be done in no time if the server was vital + $serverret = z_fetch_url($server_url."/.well-known/host-meta", false, $redirects, array('timeout' => 20)); + + // Quit if there is a timeout + if ($serverret['errno'] == CURLE_OPERATION_TIMEDOUT) { + logger("Connection to server ".$server_url." timed out.", LOGGER_DEBUG); + return false; + } $xmlobj = @simplexml_load_string($serverret["body"],'SimpleXMLElement',0, "http://docs.oasis-open.org/ns/xri/xrd-1.0"); } if (!$serverret["success"] OR ($serverret["body"] == "") OR (sizeof($xmlobj) == 0) OR !is_object($xmlobj)) { // Workaround for bad configured servers (known nginx problem) - if ($serverret["debug"]["http_code"] != "403") { + if (!in_array($serverret["debug"]["http_code"], array("403", "404"))) { $last_failure = datetime_convert(); $failure = true; }