]> git.mxchange.org Git - friendica.git/commitdiff
Fork as many processes as possible from the start on.
authorMichael Vogel <icarus@dabo.de>
Sat, 12 Sep 2015 15:51:27 +0000 (17:51 +0200)
committerMichael Vogel <icarus@dabo.de>
Sat, 12 Sep 2015 15:51:27 +0000 (17:51 +0200)
boot.php
include/poller.php

index 3bbbef3c96520e2bb4685a21f9937c00019ecf37..3116bb94b9c188bffa581ef050f4c3fa9d6c8be1 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -1449,7 +1449,25 @@ if(! function_exists('proc_run')) {
                                                dbesc(datetime_convert()),
                                                intval(0));
 
-                               return;
+                               // Should we quit and wait for the poller to be called as a cronjob?
+                               if (get_config("system", "worker_dont_fork"))
+                                       return;
+
+                               // Checking number of workers
+                               $workers = q("SELECT COUNT(*) AS `workers` FROM `workerqueue` WHERE `executed` != '0000-00-00 00:00:00'");
+
+                               // Get number of allowed number of worker threads
+                               $queues = intval(get_config("system", "worker_queues"));
+
+                               if ($queues == 0)
+                                       $queues = 4;
+
+                               // If there are already enough workers running, don't fork another one
+                               if ($workers[0]["workers"] >= $queues)
+                                       return;
+
+                               // Now call the poller to execute the jobs that we just added to the queue
+                               $args = array("php", "include/poller.php", "no_cron");
                        }
 
                        $args[0] = ((x($a->config,'php_path')) && (strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
index 74d23a548232ce53dfd8004568cc73e9249f7a71..bdf6ba84e9991af67adc8ff6441cd7ae57f77659 100644 (file)
@@ -26,15 +26,20 @@ function poller_run(&$argv, &$argc){
                unset($db_host, $db_user, $db_pass, $db_data);
        };
 
-       // Run the cron job that calls all other jobs
-       proc_run("php","include/cron.php");
-
-       // Cleaning killed processes
-       $r = q("SELECT DISTINCT(`pid`) FROM `workerqueue` WHERE `executed` != '0000-00-00 00:00:00'");
-       foreach($r AS $pid)
-               if (!posix_kill($pid["pid"], 0))
-                       q("UPDATE `workerqueue` SET `executed` = '0000-00-00 00:00:00', `pid` = 0 WHERE `pid` = %d",
-                               intval($pid["pid"]));
+       if(($argc <= 1) OR ($argv[1] != "no_cron")) {
+               // Run the cron job that calls all other jobs
+               proc_run("php","include/cron.php");
+
+               // Cleaning dead processes
+               $r = q("SELECT DISTINCT(`pid`) FROM `workerqueue` WHERE `executed` != '0000-00-00 00:00:00'");
+               foreach($r AS $pid)
+                       if (!posix_kill($pid["pid"], 0))
+                               q("UPDATE `workerqueue` SET `executed` = '0000-00-00 00:00:00', `pid` = 0 WHERE `pid` = %d",
+                                       intval($pid["pid"]));
+
+       } else
+               // Sleep two seconds before checking for running processes to avoid having too many workers
+               sleep(2);
 
        // Checking number of workers
        $workers = q("SELECT COUNT(*) AS `workers` FROM `workerqueue` WHERE `executed` != '0000-00-00 00:00:00'");