Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

worker.php 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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\Config\Cache;
  10. use Friendica\Core\Update;
  11. use Friendica\Core\Worker;
  12. use Friendica\Factory;
  13. use Friendica\Util\BasePath;
  14. // Get options
  15. $shortopts = 'sn';
  16. $longopts = ['spawn', 'no_cron'];
  17. $options = getopt($shortopts, $longopts);
  18. // Ensure that worker.php is executed from the base path of the installation
  19. if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) {
  20. $directory = dirname($_SERVER["argv"][0]);
  21. if (substr($directory, 0, 1) != '/') {
  22. $directory = $_SERVER["PWD"] . '/' . $directory;
  23. }
  24. $directory = realpath($directory . '/..');
  25. chdir($directory);
  26. }
  27. require dirname(__DIR__) . '/vendor/autoload.php';
  28. $basedir = BasePath::create(dirname(__DIR__), $_SERVER);
  29. $configLoader = new Cache\ConfigCacheLoader($basedir);
  30. $configCache = Factory\ConfigFactory::createCache($configLoader);
  31. Factory\DBFactory::init($configCache, $_SERVER);
  32. $config = Factory\ConfigFactory::createConfig($configCache);
  33. $pconfig = Factory\ConfigFactory::createPConfig($configCache);
  34. $logger = Factory\LoggerFactory::create('worker', $config);
  35. $profiler = Factory\ProfilerFactory::create($logger, $config);
  36. $a = new App($config, $logger, $profiler);
  37. // Check the database structure and possibly fixes it
  38. Update::check($a->getBasePath(), true);
  39. // Quit when in maintenance
  40. if (!$a->getMode()->has(App\Mode::MAINTENANCEDISABLED)) {
  41. return;
  42. }
  43. $a->setBaseURL(Config::get('system', 'url'));
  44. $spawn = array_key_exists('s', $options) || array_key_exists('spawn', $options);
  45. if ($spawn) {
  46. Worker::spawnWorker();
  47. exit();
  48. }
  49. $run_cron = !array_key_exists('n', $options) && !array_key_exists('no_cron', $options);
  50. Worker::processQueue($run_cron);
  51. Worker::unclaimProcess();
  52. Worker::endProcess();