]> git.mxchange.org Git - friendica.git/commitdiff
Moved some functionality back to the cron. Speed up things
authorMichael Vogel <icarus@dabo.de>
Fri, 11 Sep 2015 19:35:58 +0000 (21:35 +0200)
committerMichael Vogel <icarus@dabo.de>
Fri, 11 Sep 2015 19:35:58 +0000 (21:35 +0200)
include/cron.php
include/follow.php
include/onepoll.php
include/poller.php
include/queue.php
include/socgraph.php

index ea7fd2c6060606c9d61a18f8ec97c96d5fa8cbe6..712befb1fff58097394d6b04ea8970955bb0361f 100644 (file)
@@ -52,6 +52,20 @@ function cron_run(&$argv, &$argc){
                }
        }
 
+       $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');
@@ -75,6 +89,22 @@ function cron_run(&$argv, &$argc){
 
        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
@@ -299,6 +329,8 @@ function cron_run(&$argv, &$argc){
 
        logger('cron: end');
 
+       set_config('system','last_cron', time());
+
        return;
 }
 
index 217b9d07b7b37c22de81af99793c6cd968b1146f..ca0228cc0f89542f3f66ae7531de0fe3c68e6329 100644 (file)
@@ -9,13 +9,13 @@ function update_contact($id) {
 
        $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;
 
@@ -29,7 +29,7 @@ function update_contact($id) {
        }
 
        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']),
@@ -42,6 +42,8 @@ function update_contact($id) {
                dbesc($ret['poco']),
                intval($id)
        );
+
+       return true;
 }
 
 //
index e8fc97b21e9676c44cf03a34ac6c0ab130f0010a..0e58a776ca2d1c47a801561cfc18c9d71dea5135 100644 (file)
@@ -168,8 +168,18 @@ function onepoll_run(&$argv, &$argc){
        );
 
        // 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) {
 
index 05e936936c2446be046967ea09c53d606e0c9c97..74d23a548232ce53dfd8004568cc73e9249f7a71 100644 (file)
@@ -26,23 +26,7 @@ function poller_run(&$argv, &$argc){
                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
@@ -81,7 +65,7 @@ function poller_run(&$argv, &$argc){
                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"]));
index 0edd64fdb1bec08558c233e670e9a5f08a182c73..3f6686ec6e1c8f09c2220ca41c78be8695768f43 100644 (file)
@@ -22,6 +22,7 @@ function queue_run(&$argv, &$argc){
        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');
@@ -88,7 +89,7 @@ function queue_run(&$argv, &$argc){
        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 ))");
        }
@@ -107,7 +108,7 @@ function queue_run(&$argv, &$argc){
 
        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) {
@@ -132,12 +133,18 @@ function queue_run(&$argv, &$argc){
                        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'])
                );
@@ -194,9 +201,9 @@ function queue_run(&$argv, &$argc){
                                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;
 
index 6e2b6ea1588e8aba6f2f584ff9a709ffe74197de..1a92a7256684761358582d7a7677d11df686527e 100644 (file)
@@ -234,7 +234,7 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca
        }
 
        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;
@@ -1296,8 +1296,11 @@ function poco_discover($complete = false) {
        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";
@@ -1338,10 +1341,13 @@ function poco_discover($complete = false) {
                                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"]));
+                       }
                }
 }