This commit is contained in:
parent
1fcf0bf1da
commit
cf8bf9a9cf
1 changed files with 9 additions and 24 deletions
|
@ -515,32 +515,17 @@ function searchWikis($path, $pattern, $depth = 1, $httpCheck = false)
|
|||
// Process HTTP requests in smaller batches to avoid overwhelming resources
|
||||
if (!empty($list) && $httpCheck) {
|
||||
try {
|
||||
// Process in batches of 10 for better performance
|
||||
$batchSize = 10;
|
||||
$batches = array_chunk($list, $batchSize, true);
|
||||
|
||||
foreach ($batches as $batch) {
|
||||
$httpClient = HttpClientBuilder::buildDefault();
|
||||
$futures = [];
|
||||
|
||||
foreach ($batch as $key => $item) {
|
||||
if ($item['URL'] !== 'KO') {
|
||||
$futures[$key] = Amp\async(fn () => $httpClient->request(new Request($item['URL'], 'HEAD')));
|
||||
}
|
||||
}
|
||||
|
||||
$responses = Amp\Future\awaitAll($futures);
|
||||
|
||||
// Update statuses from responses
|
||||
foreach ($responses[0] as $key => $error) {
|
||||
$responses = Amp\Future\awaitAll(array_map(function ($l) use ($httpClient) {
|
||||
return Amp\async(fn () => $httpClient->request(new Request($l['URL'], 'HEAD')));
|
||||
}, $list));
|
||||
foreach ($responses[0] as $key => $response) {
|
||||
$list[$key]['STATUS'] = 'ERROR';
|
||||
}
|
||||
|
||||
foreach ($responses[1] 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";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue