From e79364ffc76b8ad6755759660aa6921620e013a6 Mon Sep 17 00:00:00 2001 From: yggverse Date: Thu, 5 Mar 2026 01:56:48 +0200 Subject: [PATCH] remove crontab dependency (use inline queue with caching proxy) --- README.md | 40 --------------- composer.lock | 8 +-- src/Controller/MainController.php | 17 +++++-- .../CrawlerService.php} | 50 ++++--------------- 4 files changed, 27 insertions(+), 88 deletions(-) rename src/{Controller/CrontabController.php => Service/CrawlerService.php} (89%) diff --git a/README.md b/README.md index 9726916..8d4eac5 100644 --- a/README.md +++ b/README.md @@ -31,46 +31,6 @@ Project initially written to explore [Yggdrasil](https://github.com/yggdrasil-ne * `chown -R www-data:www-data var` * `cp .env .env.local` -* `crontab -e` > `* * * * * /usr/bin/curl --silent http://localhost/crontab/index &> /dev/null` - -#### Nginx - -``` -map $request_uri $loggable { - ~^/crontab/index 0; - default 1; -} - -server { - listen [::]:27080; - - server_name hl.ygg ygg.hl.srv; - - access_log /var/log/nginx/hl.access.log combined if=$loggable; - error_log /var/log/nginx/hl.error.log warn; - - root /var/www/hlstate/HLState/public; - - index index.php index.html; - - location / { - try_files $uri /index.php$is_args$args; - } - location ~ ^/index\.php(/|$) { - fastcgi_pass unix:/run/php/php8.4-fpm.sock; - fastcgi_split_path_info ^(.+\.php)(/.*)$; - include fastcgi_params; - - fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; - fastcgi_param DOCUMENT_ROOT $realpath_root; - - internal; - } - location ~ \.php$ { - return 404; - } -} -``` ### Update diff --git a/composer.lock b/composer.lock index 14a0ecc..34aaa6b 100644 --- a/composer.lock +++ b/composer.lock @@ -8070,12 +8070,12 @@ "source": { "type": "git", "url": "https://github.com/YGGverse/hl-php.git", - "reference": "795f3047895a875c35f426c5f9d8649967f7b3db" + "reference": "9f4e92459283f6775127f0bba8fad0ed1ce88dbf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/YGGverse/hl-php/zipball/795f3047895a875c35f426c5f9d8649967f7b3db", - "reference": "795f3047895a875c35f426c5f9d8649967f7b3db", + "url": "https://api.github.com/repos/YGGverse/hl-php/zipball/9f4e92459283f6775127f0bba8fad0ed1ce88dbf", + "reference": "9f4e92459283f6775127f0bba8fad0ed1ce88dbf", "shasum": "" }, "default-branch": true, @@ -8108,7 +8108,7 @@ "issues": "https://github.com/YGGverse/hl-php/issues", "source": "https://github.com/YGGverse/hl-php/tree/main" }, - "time": "2026-03-04T23:08:13+00:00" + "time": "2026-03-04T23:11:24+00:00" } ], "packages-dev": [ diff --git a/src/Controller/MainController.php b/src/Controller/MainController.php index 918bbcf..b6eec4b 100644 --- a/src/Controller/MainController.php +++ b/src/Controller/MainController.php @@ -2,6 +2,12 @@ namespace App\Controller; +use App\Entity\Online; +use App\Entity\Player; +use App\Entity\Server; + +use App\Service\CrawlerService; + use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Contracts\Translation\TranslatorInterface; @@ -9,10 +15,6 @@ use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Request; -use App\Entity\Online; -use App\Entity\Player; -use App\Entity\Server; - use Doctrine\ORM\EntityManagerInterface; class MainController extends AbstractController @@ -27,6 +29,7 @@ class MainController extends AbstractController )] public function index( ?Request $request, + CrawlerService $crawlerService, TranslatorInterface $translatorInterface, EntityManagerInterface $entityManagerInterface ): Response @@ -39,6 +42,12 @@ class MainController extends AbstractController $this->getParameter('app.memcached.timeout') + time(), ); + // Run crawler queue + $crawlerService->crawl( + (array) explode(',', $this->getParameter('app.masters')), + $entityManagerInterface + ); + // Collect servers info $servers = []; diff --git a/src/Controller/CrontabController.php b/src/Service/CrawlerService.php similarity index 89% rename from src/Controller/CrontabController.php rename to src/Service/CrawlerService.php index 24b78be..bfcfdbb 100644 --- a/src/Controller/CrontabController.php +++ b/src/Service/CrawlerService.php @@ -1,52 +1,25 @@ trans('Process locked by another thread') - ); - } - // Get new servers from masters - foreach ((array) explode(',', $this->getParameter('app.masters')) as $master) + foreach ($masters as $master) { $master_url = "udp://" . ltrim($master, "udp://"); // @TODO IPv6 https://bugs.php.net/bug.php?id=72811 @@ -347,8 +320,5 @@ class CrontabController extends AbstractController $node->Disconnect(); } } - - // Render response - return new Response(); // @TODO } } \ No newline at end of file