X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=include%2Fcronhooks.php;h=a519dee22433650e5839d6e4ed71e53f06dcd408;hb=c7e1a8e871363d4e60178e30e819c3169ed406c5;hp=d5daf0d7d447a2beb4bb7a769872dd3b410b6dbf;hpb=58cea137075e88a6e86712d3603f8233d7adb56f;p=friendica.git diff --git a/include/cronhooks.php b/include/cronhooks.php index d5daf0d7d4..a519dee224 100644 --- a/include/cronhooks.php +++ b/include/cronhooks.php @@ -1,67 +1,53 @@ hooks) AND array_key_exists("cron", $a->hooks)) { + foreach ($a->hooks["cron"] as $hook) { + if ($hook[1] == $argv[1]) { + logger("Calling cron hook '" . $hook[1] . "'", LOGGER_DEBUG); + call_single_hook($a, $name, $hook, $data); + } + } + return; } - if(is_null($db)) { - @include(".htconfig.php"); - require_once("include/dba.php"); - $db = new dba($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - }; - - require_once('include/session.php'); - require_once('include/datetime.php'); - require_once('include/pidfile.php'); + $last = get_config('system', 'last_cronhook'); - load_config('config'); - load_config('system'); - - $maxsysload = intval(get_config('system','maxloadavg')); - if($maxsysload < 1) - $maxsysload = 50; - if(function_exists('sys_getloadavg')) { - $load = sys_getloadavg(); - if(intval($load[0]) > $maxsysload) { - logger('system: load ' . $load . ' too high. Poller deferred to next scheduled run.'); - return; - } + $poll_interval = intval(get_config('system', 'cronhook_interval')); + if (! $poll_interval) { + $poll_interval = 9; } - $lockpath = get_config('system','lockpath'); - if ($lockpath != '') { - $pidfile = new pidfile($lockpath, 'cron.lck'); - if($pidfile->is_already_running()) { - logger("cronhooks: Already running"); - exit; + if ($last) { + $next = $last + ($poll_interval * 60); + if ($next > time()) { + logger('cronhook intervall not reached'); + return; } } - $a->set_baseurl(get_config('system','url')); - - load_hooks(); + $a->set_baseurl(get_config('system', 'url')); logger('cronhooks: start'); $d = datetime_convert(); - set_time_limit(9*60*60); // Setting the maximum execution time for cronjobs to 9 minutes. - - call_hooks('cron', $d); + if (is_array($a->hooks) AND array_key_exists("cron", $a->hooks)) { + foreach ($a->hooks["cron"] as $hook) { + logger("Calling cronhooks for '" . $hook[1] . "'", LOGGER_DEBUG); + proc_run(PRIORITY_MEDIUM, "include/cronhooks.php", $hook[1]); + } + } logger('cronhooks: end'); - return; -} + set_config('system', 'last_cronhook', time()); -if (array_search(__file__,get_included_files())===0){ - cronhooks_run($argv,$argc); - killme(); + return; }