X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=bin%2Fworker.php;h=c855f9bc559d28aef36440fad5f9bead55cca7bf;hb=ddc3c0db03267d29ace272b504dc6f803fa02990;hp=469dcb001e6419accd062df13597abc705cfbf2d;hpb=36ba7fa79c7c2d4304f3423d84215771e3bb6a9f;p=friendica.git diff --git a/bin/worker.php b/bin/worker.php index 469dcb001e..c855f9bc55 100755 --- a/bin/worker.php +++ b/bin/worker.php @@ -1,16 +1,38 @@ #!/usr/bin/env php . + * + * Starts the background processing */ +if (php_sapi_name() !== 'cli') { + header($_SERVER["SERVER_PROTOCOL"] . ' 403 Forbidden'); + exit(); +} + use Dice\Dice; use Friendica\App; -use Friendica\BaseObject; -use Friendica\Core\Config; +use Friendica\App\Mode; +use Friendica\Core\Logger\Capability\LogChannel; use Friendica\Core\Update; use Friendica\Core\Worker; +use Friendica\DI; use Psr\Log\LoggerInterface; // Get options @@ -19,7 +41,7 @@ $longopts = ['spawn', 'no_cron']; $options = getopt($shortopts, $longopts); // Ensure that worker.php is executed from the base path of the installation -if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) { +if (!file_exists("index.php") && (sizeof($_SERVER["argv"]) != 0)) { $directory = dirname($_SERVER["argv"][0]); if (substr($directory, 0, 1) != '/') { @@ -33,21 +55,24 @@ if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) { require dirname(__DIR__) . '/vendor/autoload.php'; $dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php'); -$dice = $dice->addRule(LoggerInterface::class,['constructParams' => ['worker']]); +/** @var \Friendica\Core\Addon\Capability\ICanLoadAddons $addonLoader */ +$addonLoader = $dice->create(\Friendica\Core\Addon\Capability\ICanLoadAddons::class); +$dice = $dice->addRules($addonLoader->getActiveAddonConfig('dependencies')); +$dice = $dice->addRule(LoggerInterface::class, ['constructParams' => [LogChannel::WORKER]]); -BaseObject::setDependencyInjection($dice); -$a = BaseObject::getApp(); +DI::init($dice); +\Friendica\Core\Logger\Handler\ErrorHandler::register($dice->create(\Psr\Log\LoggerInterface::class)); + +DI::mode()->setExecutor(Mode::WORKER); // Check the database structure and possibly fixes it -Update::check($a->getBasePath(), true, $a->getMode()); +Update::check(DI::basePath(), true); // Quit when in maintenance -if (!$a->getMode()->has(App\Mode::MAINTENANCEDISABLED)) { +if (!DI::mode()->has(App\Mode::MAINTENANCEDISABLED)) { return; } -$a->setBaseURL(Config::get('system', 'url')); - $spawn = array_key_exists('s', $options) || array_key_exists('spawn', $options); if ($spawn) { @@ -57,8 +82,10 @@ if ($spawn) { $run_cron = !array_key_exists('n', $options) && !array_key_exists('no_cron', $options); -Worker::processQueue($run_cron); +$process = DI::process()->create(getmypid(), basename(__FILE__)); + +Worker::processQueue($run_cron, $process); -Worker::unclaimProcess(); +Worker::unclaimProcess($process); -Worker::endProcess(); +DI::process()->delete($process);