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