4 * @brief Module for running the poller as frontend process
6 require_once("include/poller.php");
8 use Friendica\Core\Worker;
9 use Friendica\Core\Config;
10 use Friendica\Core\PConfig;
12 function worker_init($a){
14 if (!Config::get("system", "frontend_worker")) {
18 // We don't need the following lines if we can execute background jobs.
19 // So we just wake up the worker if it sleeps.
20 if (function_exists("proc_open")) {
21 Worker::executeIfIdle();
25 Worker::clearProcesses();
27 $workers = q("SELECT COUNT(*) AS `processes` FROM `process` WHERE `command` = 'worker.php'");
29 if ($workers[0]["processes"] > Config::get("system", "worker_queues", 4)) {
35 logger("Front end worker started: ".getmypid());
39 if ($r = Worker::workerProcess()) {
41 // On most configurations this parameter wouldn't have any effect.
42 // But since it doesn't destroy anything, we just try to get more execution time in any way.
45 if (poller_claim_process($r[0])) {
46 Worker::execute($r[0]);
52 Worker::unclaimProcess();
56 logger("Front end worker ended: ".getmypid());