]> git.mxchange.org Git - friendica.git/blobdiff - include/queue.php
Merge remote-tracking branch 'upstream/develop' into 1509-new-feed-import
[friendica.git] / include / queue.php
index 64cccad21efe4f796a50e39b480da75415da7d12..0edd64fdb1bec08558c233e670e9a5f08a182c73 100644 (file)
@@ -8,7 +8,7 @@ function queue_run(&$argv, &$argc){
        if(is_null($a)){
                $a = new App;
        }
-  
+
        if(is_null($db)){
                @include(".htconfig.php");
                require_once("include/dba.php");
@@ -21,10 +21,26 @@ function queue_run(&$argv, &$argc){
        require_once("include/datetime.php");
        require_once('include/items.php');
        require_once('include/bbcode.php');
+       require_once('include/pidfile.php');
 
        load_config('config');
        load_config('system');
 
+       $lockpath = get_lockpath();
+       if ($lockpath != '') {
+               $pidfile = new pidfile($lockpath, 'queue');
+               if($pidfile->is_already_running()) {
+                       logger("queue: Already running");
+                       if ($pidfile->running_time() > 9*60) {
+                               $pidfile->kill();
+                               logger("queue: killed stale process");
+                               // Calling a new instance
+                               proc_run('php',"include/queue.php");
+                       }
+                       return;
+               }
+       }
+
        $a->set_baseurl(get_config('system','url'));
 
        load_hooks();
@@ -38,6 +54,9 @@ function queue_run(&$argv, &$argc){
 
        logger('queue: start');
 
+       // Handling the pubsubhubbub requests
+       proc_run('php','include/pubsubpublish.php');
+
        $interval = ((get_config('system','delivery_interval') === false) ? 2 : intval(get_config('system','delivery_interval')));
 
        $r = q("select * from deliverq where 1");
@@ -50,8 +69,8 @@ function queue_run(&$argv, &$argc){
                }
        }
 
-       $r = q("SELECT `queue`.*, `contact`.`name`, `contact`.`uid` FROM `queue` 
-               LEFT JOIN `contact` ON `queue`.`cid` = `contact`.`id` 
+       $r = q("SELECT `queue`.*, `contact`.`name`, `contact`.`uid` FROM `queue`
+               INNER JOIN `contact` ON `queue`.`cid` = `contact`.`id`
                WHERE `queue`.`created` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
        if($r) {
                foreach($r as $rr) {
@@ -60,7 +79,7 @@ function queue_run(&$argv, &$argc){
                }
                q("DELETE FROM `queue` WHERE `created` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
        }
-               
+
        if($queue_id) {
                $r = q("SELECT `id` FROM `queue` WHERE `id` = %d LIMIT 1",
                        intval($queue_id)
@@ -173,22 +192,22 @@ function queue_run(&$argv, &$argc){
                        default:
                                $params = array('owner' => $owner, 'contact' => $contact, 'queue' => $q_item, 'result' => false);
                                call_hooks('queue_deliver', $a, $params);
-               
+
                                if($params['result'])
                                                remove_queue_item($q_item['id']);
                                else
                                                update_queue_time($q_item['id']);
-       
+
                                break;
 
                }
        }
-               
+
        return;
 
 }
 
 if (array_search(__file__,get_included_files())===0){
-  queue_run($argv,$argc);
+  queue_run($_SERVER["argv"],$_SERVER["argc"]);
   killme();
 }