]> git.mxchange.org Git - friendica.git/blob - mod/worker.php
Remove include/oembed and mod/oembed
[friendica.git] / mod / worker.php
1 <?php
2 /**
3  * @file mod/worker.php
4  * @brief Module for running the worker as frontend process
5  */
6
7 use Friendica\Core\Worker;
8 use Friendica\Core\Config;
9 use Friendica\Core\PConfig;
10
11 function worker_init($a){
12
13         if (!Config::get("system", "frontend_worker")) {
14                 return;
15         }
16
17         // We don't need the following lines if we can execute background jobs.
18         // So we just wake up the worker if it sleeps.
19         if (function_exists("proc_open")) {
20                 Worker::executeIfIdle();
21                 return;
22         }
23
24         Worker::clearProcesses();
25
26         $workers = q("SELECT COUNT(*) AS `processes` FROM `process` WHERE `command` = 'worker.php'");
27
28         if ($workers[0]["processes"] > Config::get("system", "worker_queues", 4)) {
29                 return;
30         }
31
32         $a->start_process();
33
34         logger("Front end worker started: ".getmypid());
35
36         Worker::callWorker();
37
38         if ($r = Worker::workerProcess()) {
39
40                 // On most configurations this parameter wouldn't have any effect.
41                 // But since it doesn't destroy anything, we just try to get more execution time in any way.
42                 set_time_limit(0);
43
44                 if (poller_claim_process($r[0])) {
45                         Worker::execute($r[0]);
46                 }
47         }
48
49         Worker::callWorker();
50
51         Worker::unclaimProcess();
52
53         $a->end_process();
54
55         logger("Front end worker ended: ".getmypid());
56
57         killme();
58 }