this code check if a url is working. rewrite entirely to be has fast as possible.

<?php

declare(strict_types=1);

namespace App\Command;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;

#[AsCommand(
    name: 'app:check-genius-sports-urls',
    description: 'Generates letter combinations for URLs and checks them concurrently.',
)]
class CheckGeniusSportsUrlsCommand extends Command
{
    private HttpClientInterface $httpClient;
    private CacheInterface $cache;
    private const string BASE_URL = 'https://hosted.dcd.shared.geniussports.com/{letters}/';
    private ?SymfonyStyle $io = null;

    public function __construct(HttpClientInterface $httpClient, CacheInterface $cache)
    {
        parent::__construct();
        $this->httpClient = $httpClient;
        $this->cache = $cache;
    }

    protected function configure(): void
    {
        $this
            ->addArgument(
                'length',
                InputArgument::REQUIRED,
                'The number of capital letters for the combinations (e.g., 2 for AA-ZZ).',
            )
            ->addOption(
                'batch-size',
                'b',
                InputOption::VALUE_OPTIONAL,
                'Number of URLs to process concurrently in a batch.',
                500,
            )
            ->addOption(
                'timeout',
                null,
                InputOption::VALUE_OPTIONAL,
                'Request timeout in seconds for each request.',
                1
            )
            ->addOption(
                'cache-lifetime',
                null,
                InputOption::VALUE_OPTIONAL,
                'Cache lifetime in seconds for each URL result.',
                7 * 24 * 60 * 60,
            );
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $this->io = new SymfonyStyle($input, $output);
        $length = (int)$input->getArgument('length');
        $batchSize = (int)$input->getOption('batch-size');
        $timeout = (float)$input->getOption('timeout');
        $cacheLifetime = (int)$input->getOption('cache-lifetime');

        if ($length <= 0) {
            $this->io->error('Length must be a positive integer.');
            return Command::INVALID;
        }
        if ($batchSize <= 0) {
            $this->io->error('Batch size must be a positive integer.');
            return Command::INVALID;
        }

        $successfulUrls = [];
        $characters = range('A', 'Z');
        $numChars = count($characters);

        $estimatedTotalIterations = pow($numChars, $length);
        $maxProgressSteps = 0;
        if (is_finite(
                $estimatedTotalIterations,
            ) && $estimatedTotalIterations > 0 && $estimatedTotalIterations <= PHP_INT_MAX) {
            $maxProgressSteps = (int)$estimatedTotalIterations;
        }
        $this->io->progressStart($maxProgressSteps);

        $indices = array_fill(0, $length, 0);
        $keepGenerating = $length > 0;
        $urlBatch = [];

        while ($keepGenerating) {
            $currentCombination = '';
            foreach ($indices as $index) {
                $currentCombination .= $characters[$index];
            }

            // Advance progress for each generated combination
            if ($maxProgressSteps > 0) {
                $this->io->progressAdvance();
            } else {
                $this->io->progressAdvance(0);
            }

            $urlBatch[] = str_replace('{letters}', $currentCombination, self::BASE_URL);

            // Increment indices for the next combination
            $pos = $length - 1;
            while ($pos >= 0) {
                $indices[$pos]++;
                if ($indices[$pos] < $numChars) {
                    break;
                }
                $indices[$pos] = 0;
                $pos--;
            }

            if ($pos < 0) {
                $keepGenerating = false;
            }

            // Process batch if full or if it's the last iteration and batch has items
            if (count($urlBatch) > 0 && (count($urlBatch) >= $batchSize || !$keepGenerating)) {
                $this->processUrlBatch($urlBatch, $successfulUrls, $timeout, $cacheLifetime);
                $urlBatch = []; // Reset for next batch
            }
        }

        $this->io->progressFinish();

        if (!empty($successfulUrls)) {
            $this->io->success('Successfully retrieved content from the following URLs:');
            $this->io->listing($successfulUrls);
        } else {
            $this->io->note('No URLs returned content successfully with the generated combinations.');
        }

        return Command::SUCCESS;
    }

    private function processUrlBatch(
        array $urlsInBatch,
        array &$successfulUrls,
        float $timeout,
        int $cacheLifetime,
    ): void {
        if (empty($urlsInBatch) || $this->io === null) {
            return;
        }

        // Separate cached and non-cached URLs
        $cachedResults = [];
        $urlsToFetch = [];

        foreach ($urlsInBatch as $url) {
            $cacheKey = 'genius_url_' . md5($url);
            if ($this->cache->hasItem($cacheKey)) {
                $result = $this->cache->getItem($cacheKey)->get();
                if ($result) {
                    $cachedResults[] = $result;
                }
            } else {
                $urlsToFetch[] = $url;
            }
        }

        // Add cached results immediately
        $successfulUrls = array_merge($successfulUrls, $cachedResults);

        if (empty($urlsToFetch)) {
            return;
        }

        // Process non-cached URLs concurrently
        $responses = [];
        foreach ($urlsToFetch as $url) {
            $responses[$url] = $this->httpClient->request('GET', $url, [
                'timeout' => $timeout,
                'max_redirects' => 1,
            ]);
        }

        // Process responses as they complete
        foreach ($responses as $url => $response) {
            $cacheKey = 'genius_url_' . md5($url);
            try {
                $statusCode = $response->getStatusCode();
                if ($statusCode >= 200 && $statusCode < 300) {
                    $content = $response->getContent(false);
                    if (strlen(trim($content)) > 0) {
                        $result = $this->extractValidUrl($content, $url);
                        if ($result) {
                            $successfulUrls[] = $result;
                            $this->cacheResult($cacheKey, $result, $cacheLifetime);
                            if ($this->io->isVerbose()) {
                                $this->io->writeln(" <info>SUCCESS:</info> {$result}");
                            }
                        }
                    }
                }
            } catch (TransportExceptionInterface|\Exception) {
                $this->cacheResult($cacheKey, null, 1); // Cache failures briefly
            }
        }
    }

    private function extractValidUrl(string $content, string $fallbackUrl): ?string
    {
        preg_match('/validateSetup\\(2,(.*)\\);/', $content, $matches);
        if (isset($matches[1]) && is_string($matches[1]) && strlen($matches[1]) > 0) {
            preg_match("/,'([a-z]+\.web\.geniussports\.com)'/", $matches[1], $validUrl);
            if (isset($validUrl[1])) {
                return 'https://' . $validUrl[1];
            }
        }
        return $fallbackUrl;
    }

    private function cacheResult(string $cacheKey, ?string $result, int $lifetime): void
    {
        $item = $this->cache->getItem($cacheKey);
        $item->set($result);
        $item->expiresAfter($lifetime);
        $this->cache->save($item);
    }
}