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