]> git.mxchange.org Git - friendica.git/blobdiff - include/discover_poco.php
Merge remote-tracking branch 'upstream/develop' into 1702-detect-server
[friendica.git] / include / discover_poco.php
index 6a3df27c8c67c820eccbb92ddbc93818c7d984b0..91cc0b6083a123622fad7c68514be6a68e643798 100644 (file)
@@ -29,6 +29,15 @@ function discover_poco_run(&$argv, &$argc){
                if ($a->maxload_reached())
                        return;
 
+       /*
+       This function can be called in these ways:
+       - dirsearch <search pattern>: Searches for "search pattern" in the directory. "search pattern" is url encoded.
+       - checkcontact: Updates gcontact entries
+       - suggestions: Discover other servers for their contacts.
+       - server <poco url>: Searches for the poco server list. "poco url" is base64 encoded.
+       - update_server: Frequently check the first 250 servers for vitality.
+       */
+
        if(($argc > 2) && ($argv[1] == "dirsearch")) {
                $search = urldecode($argv[2]);
                $mode = 1;
@@ -38,6 +47,8 @@ function discover_poco_run(&$argv, &$argc){
                $mode = 3;
        } elseif(($argc == 3) && ($argv[1] == "server")) {
                $mode = 4;
+       } elseif(($argc == 2) && ($argv[1] == "update_server")) {
+               $mode = 5;
        } elseif ($argc == 1) {
                $search = "";
                $mode = 0;
@@ -56,7 +67,9 @@ function discover_poco_run(&$argv, &$argc){
 
        logger('start '.$search);
 
-       if ($mode == 4) {
+       if ($mode == 5) {
+               update_server();
+       } elseif ($mode == 4) {
                $server_url = base64_decode($argv[2]);
                if ($server_url == "") {
                        return;
@@ -94,6 +107,33 @@ function discover_poco_run(&$argv, &$argc){
        return;
 }
 
+/**
+ * @brief Updates the first 250 servers
+ *
+ */
+function update_server() {
+       $r = q("SELECT `url`, `created`, `last_failure`, `last_contact` FROM `gserver` ORDER BY rand()");
+
+       if (!dbm::is_result($r)) {
+               return;
+       }
+
+       $updated = 0;
+
+       foreach ($r AS $server) {
+               if (!poco_do_update($server["created"], "", $server["last_failure"], $server["last_contact"])) {
+                       continue;
+               }
+               logger('Update server status for server '.$server["url"], LOGGER_DEBUG);
+
+               proc_run(PRIORITY_LOW, "include/discover_poco.php", "server", base64_encode($server["url"]));
+
+               if (++$updated > 250) {
+                       return;
+               }
+       }
+}
+
 function discover_users() {
        logger("Discover users", LOGGER_DEBUG);