]> git.mxchange.org Git - friendica.git/blobdiff - include/poller.php
Issue 3857: There is the possibility of a bad handling of dislikes
[friendica.git] / include / poller.php
index 8c30d1628545e9ee5f3f41ce42804b04ec2d065a..b8f0d7189fdf76f761966c255e79d6e3ef800956 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 
 use Friendica\App;
+use Friendica\Core\System;
 use Friendica\Core\Config;
 use Friendica\Util\Lock;
 
@@ -18,19 +19,24 @@ if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) {
 require_once("boot.php");
 
 function poller_run($argv, $argc){
-       global $a, $db, $poller_up_start, $poller_db_duration;
+       global $a, $poller_up_start, $poller_db_duration;
 
        $poller_up_start = microtime(true);
 
-       $a = new App(dirname(__DIR__));
+       if (empty($a)) {
+               $a = new App(dirname(__DIR__));
+       }
 
-       @include(".htconfig.php");
-       require_once("include/dba.php");
-       $db = new dba($db_host, $db_user, $db_pass, $db_data);
+       require_once ".htconfig.php";
+       require_once "include/dba.php";
+       dba::connect($db_host, $db_user, $db_pass, $db_data);
        unset($db_host, $db_user, $db_pass, $db_data);
 
        Config::load();
 
+       // Check the database structure and possibly fixes it
+       check_db(true);
+
        // Quit when in maintenance
        if (Config::get('system', 'maintenance', true)) {
                return;
@@ -247,7 +253,9 @@ function poller_execute($queue) {
                poller_exec_function($queue, $funcname, $argv);
 
                $stamp = (float)microtime(true);
-               dba::update('workerqueue', array('done' => true), array('id' => $queue["id"]));
+               if (dba::update('workerqueue', array('done' => true), array('id' => $queue["id"]))) {
+                       Config::set('system', 'last_poller_execution', datetime_convert());
+               }
                $poller_db_duration = (microtime(true) - $stamp);
        } else {
                logger("Function ".$funcname." does not exist");
@@ -302,6 +310,9 @@ function poller_exec_function($queue, $funcname, $argv) {
 
        $up_duration = number_format(microtime(true) - $poller_up_start, 3);
 
+       // Reset global data to avoid interferences
+       unset($_SESSION);
+
        $funcname($argv, $argc);
 
        $a->process_id = $old_process_id;
@@ -686,7 +697,7 @@ function find_worker_processes(&$passing_slow) {
        // The higher the number of parallel workers, the more we prefetch to prevent concurring access
        // We decrease the limit with the number of entries left in the queue
        $worker_queues = Config::get("system", "worker_queues", 4);
-       $queue_length = Config::get('system', 'worker_fetch_limit', $worker_queues);
+       $queue_length = Config::get('system', 'worker_fetch_limit', 1);
        $lower_job_limit = $worker_queues * $queue_length * 2;
        $jobs = poller_total_entries();
 
@@ -799,7 +810,7 @@ function call_worker() {
                return;
        }
 
-       $url = App::get_baseurl()."/worker";
+       $url = System::baseUrl()."/worker";
        fetch_url($url, false, $redirects, 1);
 }
 
@@ -883,7 +894,7 @@ function poller_run_cron() {
        poller_kill_stale_workers();
 }
 
-if (array_search(__file__,get_included_files())===0){
+if (array_search(__file__,get_included_files())===0) {
        poller_run($_SERVER["argv"],$_SERVER["argc"]);
 
        poller_unclaim_process();