- if(count($args) && $args[0] === 'php') {
-
- if (get_config("system", "worker")) {
- $argv = $args;
- array_shift($argv);
-
- $parameters = json_encode($argv);
- $found = q("SELECT `id` FROM `workerqueue` WHERE `parameter` = '%s'",
- dbesc($parameters));
-
- $funcname = str_replace(".php", "", basename($argv[0]))."_run";
-
- // Define the processes that have priority over any other process
- /// @todo Better check for priority processes
- $high_priority = array("delivery_run", "notifier_run", "pubsubpublish_run");
- $low_priority = array("queue_run", "gprobe_run", "discover_poco_run");
-
- if (in_array($funcname, $high_priority))
- $priority = 1;
- elseif (in_array($funcname, $low_priority))
- $priority = 3;
- else
- $priority = 2;
-
- if (!$found)
- // quickfix for the delivery problems, 2106-07-28
- /// @todo find better solution
- //q("INSERT INTO `workerqueue` (`function`, `parameter`, `created`, `priority`)
- // VALUES ('%s', '%s', '%s', %d)",
- // dbesc($funcname),
- q("INSERT INTO `workerqueue` (`parameter`, `created`, `priority`)
- VALUES ('%s', '%s', %d)",
- dbesc($parameters),
- dbesc(datetime_convert()),
- intval($priority));
-
- // 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');