]> git.mxchange.org Git - friendica.git/blob - bin/worker.php
Merge pull request #7962 from MrPetovan/bug/fatal-errors
[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 use Psr\Log\LoggerInterface;
15
16 // Get options
17 $shortopts = 'sn';
18 $longopts = ['spawn', 'no_cron'];
19 $options = getopt($shortopts, $longopts);
20
21 // Ensure that worker.php is executed from the base path of the installation
22 if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) {
23         $directory = dirname($_SERVER["argv"][0]);
24
25         if (substr($directory, 0, 1) != '/') {
26                 $directory = $_SERVER["PWD"] . '/' . $directory;
27         }
28         $directory = realpath($directory . '/..');
29
30         chdir($directory);
31 }
32
33 require dirname(__DIR__) . '/vendor/autoload.php';
34
35 $dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php');
36 $dice = $dice->addRule(LoggerInterface::class,['constructParams' => ['worker']]);
37
38 BaseObject::setDependencyInjection($dice);
39 $a = BaseObject::getApp();
40
41 // Check the database structure and possibly fixes it
42 Update::check($a->getBasePath(), true, $a->getMode());
43
44 // Quit when in maintenance
45 if (!$a->getMode()->has(App\Mode::MAINTENANCEDISABLED)) {
46         return;
47 }
48
49 $a->setBaseURL(Config::get('system', 'url'));
50
51 $spawn = array_key_exists('s', $options) || array_key_exists('spawn', $options);
52
53 if ($spawn) {
54         Worker::spawnWorker();
55         exit();
56 }
57
58 $run_cron = !array_key_exists('n', $options) && !array_key_exists('no_cron', $options);
59
60 Worker::processQueue($run_cron);
61
62 Worker::unclaimProcess();
63
64 Worker::endProcess();