]> git.mxchange.org Git - friendica.git/blob - bin/worker.php
9b396c6f9c5d978eeec51f570f55430970993854
[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 use Friendica\Util\BasePath;
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 $basedir = BasePath::create(dirname(__DIR__), $_SERVER);
35 $configLoader = new Config\ConfigCacheLoader($basedir);
36 $config = Factory\ConfigFactory::createCache($configLoader);
37 $logger = Factory\LoggerFactory::create('worker', $config);
38 $profiler = Factory\ProfilerFactory::create($logger, $config);
39
40 $a = new App($config, $logger, $profiler);
41
42 // Check the database structure and possibly fixes it
43 Update::check($a->getBasePath(), true);
44
45 // Quit when in maintenance
46 if (!$a->getMode()->has(App\Mode::MAINTENANCEDISABLED)) {
47         return;
48 }
49
50 $a->setBaseURL(Config::get('system', 'url'));
51
52 $spawn = array_key_exists('s', $options) || array_key_exists('spawn', $options);
53
54 if ($spawn) {
55         Worker::spawnWorker();
56         exit();
57 }
58
59 $run_cron = !array_key_exists('n', $options) && !array_key_exists('no_cron', $options);
60
61 Worker::processQueue($run_cron);
62
63 Worker::unclaimProcess();
64
65 Worker::endProcess();