feat(updater) : test status of urls async

This commit is contained in:
Florian Schmitt 2024-01-09 22:12:15 +03:00
parent 0cb608e80b
commit 807b374fbc
3 changed files with 1653 additions and 23 deletions

View file

@ -2,6 +2,8 @@
"require": { "require": {
"league/climate": "^3.8", "league/climate": "^3.8",
"devcoder-xyz/php-dotenv": "^1.1", "devcoder-xyz/php-dotenv": "^1.1",
"league/plates": "^3.4" "league/plates": "^3.4",
"amphp/parallel": "^2.2",
"amphp/http-client": "^5.0"
} }
} }

1633
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -2,6 +2,10 @@
require 'vendor/autoload.php'; require 'vendor/autoload.php';
use Amp\Future;
use Amp\Http\Client\HttpClientBuilder;
use Amp\Http\Client\Request;
function checkIP($domain, $withWww = false, $noip6 = false) function checkIP($domain, $withWww = false, $noip6 = false)
{ {
if (!preg_match('/(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]\.)+[a-zA-Z]{2,63}$)/', strtolower($domain))) { if (!preg_match('/(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]\.)+[a-zA-Z]{2,63}$)/', strtolower($domain))) {
@ -343,6 +347,7 @@ function searchWikis($path, $pattern)
{ {
$it = new RecursiveDirectoryIterator($path); $it = new RecursiveDirectoryIterator($path);
$list = array(); $list = array();
$httpClient = HttpClientBuilder::buildDefault();
$nb = 0; $nb = 0;
foreach (new RecursiveIteratorIterator($it) as $file) { foreach (new RecursiveIteratorIterator($it) as $file) {
if (preg_match('/' . preg_quote($pattern) . '$/i', $file)) { if (preg_match('/' . preg_quote($pattern) . '$/i', $file)) {
@ -354,27 +359,21 @@ function searchWikis($path, $pattern)
'VERSION' => $wakkaConfig['yeswiki_version'] ?? 'KO', 'VERSION' => $wakkaConfig['yeswiki_version'] ?? 'KO',
'RELEASE' => $wakkaConfig['yeswiki_release'] ?? 'KO', 'RELEASE' => $wakkaConfig['yeswiki_release'] ?? 'KO',
]; ];
//$executions[$nb] = Worker\submit($client->request(new Request($list[$nb]['URL'] . $wakkaConfig['root_page'])));
} }
} }
try {
$responses = Future\await(array_map(function ($l) use ($httpClient) {
return Amp\async(fn () => $httpClient->request(new Request($l['URL'], 'HEAD')));
}, $list));
foreach ($responses as $key => $response) {
$list[$key]['STATUS'] = $response->getStatus() . ' ' . $response->getReason();
}
} catch (Exception $e) {
// If any one of the requests fails the combo will fail
echo $e->getMessage(), "\n";
}
return $list; return $list;
} }