diff --git a/app/controllers/general.php b/app/controllers/general.php index 1efb9ab4b7..cc38a2ef44 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -34,6 +34,7 @@ use Appwrite\Utopia\View; use Executor\Executor; use MaxMind\Db\Reader; use Swoole\Http\Request as SwooleRequest; +use Swoole\Table; use Utopia\Config\Config; use Utopia\Console; use Utopia\Database\Database; @@ -1073,7 +1074,8 @@ Http::init() ->inject('queueForCertificates') ->inject('platform') ->inject('authorization') - ->action(function (Request $request, Document $console, Database $dbForPlatform, Certificate $queueForCertificates, array $platform, Authorization $authorization) use ($hostnames) { + ->inject('hostnames') + ->action(function (Request $request, Document $console, Database $dbForPlatform, Certificate $queueForCertificates, array $platform, Authorization $authorization, Table $hostnames) { $hostname = $request->getHostname(); $platformHostnames = $platform['hostnames'] ?? []; diff --git a/app/http.php b/app/http.php index be8bb05122..e921b154de 100644 --- a/app/http.php +++ b/app/http.php @@ -48,6 +48,9 @@ $hostnames = new Table(100_000); $hostnames->column('value', Table::TYPE_INT, 1); $hostnames->create(); +Http::setResource('domains', fn () => $domains); +Http::setResource('hostnames', fn () => $hostnames); + $http = new Server( host: "0.0.0.0", port: System::getEnv('PORT', 80), @@ -583,7 +586,7 @@ $http->on(Constant::EVENT_REQUEST, function (SwooleRequest $swooleRequest, Swool }); // Fetch domains every `DOMAIN_SYNC_TIMER` seconds and update in the memory -$http->on(Constant::EVENT_TASK, function () use ($register, $domains) { +$http->on(Constant::EVENT_TASK, function () use ($register) { $lastSyncUpdate = null; $pools = $register->get('pools'); Http::setResource('pools', fn () => $pools); @@ -592,6 +595,9 @@ $http->on(Constant::EVENT_TASK, function () use ($register, $domains) { /** @var Utopia\Database\Database $dbForPlatform */ $dbForPlatform = $app->getResource('dbForPlatform'); + /** @var Table $domains */ + $domains = $app->getResource('domains'); + Timer::tick(DOMAIN_SYNC_TIMER * 1000, function () use ($dbForPlatform, $domains, &$lastSyncUpdate, $app) { try { $time = DateTime::now();