Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
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.

65 lines
1.5KB

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