]> git.mxchange.org Git - friendica.git/blobdiff - include/notifier.php
Merge remote-tracking branch 'friendika/master' into newui
[friendica.git] / include / notifier.php
index aa186317f967de1eb736a2360c944b205f44da34..6ac882c1992cf96511901f3c6f54033444aaffc2 100644 (file)
@@ -2,6 +2,20 @@
 
 require_once("boot.php");
 
+/*
+ * This file was at one time responsible for doing all deliveries, but this caused
+ * big problems on shared hosting systems, where the process might get killed by the 
+ * hosting provider and nothing would get delivered. 
+ * It now only delivers one message under certain cases, and invokes a queued
+ * delivery mechanism (include/deliver.php) to deliver individual contacts at 
+ * controlled intervals.
+ * This has a much better chance of surviving random processes getting killed
+ * by the hosting provider. 
+ * A lot of this code is duplicated in include/deliver.php until we have time to go back
+ * and re-structure the delivery procedure based on the obstacles that have been thrown at 
+ * us by hosting providers. 
+ */
+
 function notifier_run($argv, $argc){
        global $a, $db;
 
@@ -129,6 +143,7 @@ function notifier_run($argv, $argc){
                        logger('notifier: top level post');
                        $top_level = true;
                }
+
        }
 
        $r = q("SELECT `contact`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey`, 
@@ -144,6 +159,8 @@ function notifier_run($argv, $argc){
 
        $owner = $r[0];
 
+       $walltowall = ((($top_level) && ($owner['id'] != $items[0]['contact-id'])) ? true : false);
+
        $hub = get_config('system','huburl');
 
        // If this is a public conversation, notify the feed hub
@@ -384,9 +401,7 @@ function notifier_run($argv, $argc){
 
        require_once('include/salmon.php');
 
-       $interval = intval(get_config('system','delivery_interval'));
-       if(! $interval)
-               $interval = 2;
+       $interval = ((get_config('system','delivery_interval') === false) ? 2 : intval(get_config('system','delivery_interval')));
 
        // delivery loop
 
@@ -411,7 +426,9 @@ function notifier_run($argv, $argc){
 
                        if((! $mail) && (! $fsuggest) && (! $followup)) {
                                proc_run('php','include/delivery.php',$cmd,$item_id,$contact['id']);
-                               @time_sleep_until(microtime(true) + (float) $interval);
+                               if($interval)
+                                       @time_sleep_until(microtime(true) + (float) $interval);
+                               continue;
                        }
 
                        $deliver_status = 0;
@@ -591,7 +608,8 @@ function notifier_run($argv, $argc){
                                                diaspora_send_relay($target_item,$owner,$contact);
                                                break;
                                        }               
-                                       elseif($top_level) {
+                                       elseif(($top_level) && (! $walltowall)) {
+                                               // currently no workable solution for sending walltowall
                                                diaspora_send_status($target_item,$owner,$contact);
                                                break;
                                        }
@@ -661,7 +679,8 @@ function notifier_run($argv, $argc){
                                if((! $mail) && (! $fsuggest) && (! $followup)) {
                                        logger('notifier: delivery agent: ' . $rr['name'] . ' ' . $rr['id']); 
                                        proc_run('php','include/delivery.php',$cmd,$item_id,$rr['id']);
-                                       @time_sleep_until(microtime(true) + (float) $interval);
+                                       if($interval)
+                                               @time_sleep_until(microtime(true) + (float) $interval);
                                }
                        }
                }