4 * @brief Module for running the worker as frontend process
7 use Friendica\Core\Config;
8 use Friendica\Core\Worker;
10 function worker_init(){
12 if (!Config::get("system", "frontend_worker")) {
16 // We don't need the following lines if we can execute background jobs.
17 // So we just wake up the worker if it sleeps.
18 if (function_exists("proc_open")) {
19 Worker::executeIfIdle();
23 Worker::clearProcesses();
25 $workers = q("SELECT COUNT(*) AS `processes` FROM `process` WHERE `command` = 'worker.php'");
27 if ($workers[0]["processes"] > Config::get("system", "worker_queues", 4)) {
31 Worker::startProcess();
33 logger("Front end worker started: ".getmypid());
37 if ($r = Worker::workerProcess()) {
39 // On most configurations this parameter wouldn't have any effect.
40 // But since it doesn't destroy anything, we just try to get more execution time in any way.
43 $fields = ['executed' => DateTimeFormat::utcNow(), 'pid' => getmypid(), 'done' => false];
44 $condition = ['id' => $r[0]["id"], 'pid' => 0];
45 if (dba::update('workerqueue', $fields, $condition)) {
46 Worker::execute($r[0]);
52 Worker::unclaimProcess();
56 logger("Front end worker ended: ".getmypid());