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