]> git.mxchange.org Git - friendica.git/blob - bin/worker.php
Merge pull request #6953 from tobiasd/20190330-csspath
[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 $a = Factory\DependencyFactory::setUp('worker', dirname(__DIR__));
34
35 // Check the database structure and possibly fixes it
36 Update::check($a->getBasePath(), true, $a->getMode());
37
38 // Quit when in maintenance
39 if (!$a->getMode()->has(App\Mode::MAINTENANCEDISABLED)) {
40         return;
41 }
42
43 $a->setBaseURL(Config::get('system', 'url'));
44
45 $spawn = array_key_exists('s', $options) || array_key_exists('spawn', $options);
46
47 if ($spawn) {
48         Worker::spawnWorker();
49         exit();
50 }
51
52 $run_cron = !array_key_exists('n', $options) && !array_key_exists('no_cron', $options);
53
54 Worker::processQueue($run_cron);
55
56 Worker::unclaimProcess();
57
58 Worker::endProcess();