]> git.mxchange.org Git - friendica.git/blob - bin/worker.php
Merge pull request #7465 from nupplaphil/task/dice_cache_lock
[friendica.git] / bin / worker.php
1 #!/usr/bin/env php
2 <?php
3 /**
4  * @file bin/worker.php
5  * @brief Starts the background processing
6  */
7
8 use Dice\Dice;
9 use Friendica\App;
10 use Friendica\BaseObject;
11 use Friendica\Core\Config;
12 use Friendica\Core\Update;
13 use Friendica\Core\Worker;
14
15 // Get options
16 $shortopts = 'sn';
17 $longopts = ['spawn', 'no_cron'];
18 $options = getopt($shortopts, $longopts);
19
20 // Ensure that worker.php is executed from the base path of the installation
21 if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) {
22         $directory = dirname($_SERVER["argv"][0]);
23
24         if (substr($directory, 0, 1) != '/') {
25                 $directory = $_SERVER["PWD"] . '/' . $directory;
26         }
27         $directory = realpath($directory . '/..');
28
29         chdir($directory);
30 }
31
32 require dirname(__DIR__) . '/vendor/autoload.php';
33
34 $dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php');
35
36 BaseObject::setDependencyInjection($dice);
37 $a = BaseObject::getApp();
38
39 // Check the database structure and possibly fixes it
40 Update::check($a->getBasePath(), true, $a->getMode());
41
42 // Quit when in maintenance
43 if (!$a->getMode()->has(App\Mode::MAINTENANCEDISABLED)) {
44         return;
45 }
46
47 $a->setBaseURL(Config::get('system', 'url'));
48
49 $spawn = array_key_exists('s', $options) || array_key_exists('spawn', $options);
50
51 if ($spawn) {
52         Worker::spawnWorker();
53         exit();
54 }
55
56 $run_cron = !array_key_exists('n', $options) && !array_key_exists('no_cron', $options);
57
58 Worker::processQueue($run_cron);
59
60 Worker::unclaimProcess();
61
62 Worker::endProcess();