Concurrent HTTP requests
Symfony's HttpClient comes packed with features: HTTP/2 support, automatic retries, response streaming, easy mocking in tests. Autowire it and make requests.
But requests are lazy: this loop fires all of them concurrently. The code doesn't block until you read a response.
Only when you call toArray() does the code wait, and by then most responses are already arriving. Ten API calls cost roughly the time of the slowest one, not the sum of all (and with no threads, promises or async/await involved).
<?phpnamespace App\Service;use Symfony\Contracts\HttpClient\HttpClientInterface;class GitHubStats{ public function __construct( private HttpClientInterface $client, ) { } public function getStars(array $repositories): array { // all these requests run concurrently, not one after another $responses = []; foreach ($repositories as $repository) { $responses[$repository] = $this->client->request( 'GET', "https://api.github.com/repos/$repository" ); } return array_map( fn ($response) => $response->toArray()['stargazers_count'], $responses, ); }}