i'm working on a project where i need to perform 2000 asynchronous requests using Guzzle to an endpoint and each time i need to change the ID in the url.
the endpoint looks like this: https://jsonplaceholder.typicode.com/posts/X
I tried to use a for loop to do that the only issue is that it's not asynchronous. what's the more efficient way to do such task?
use GuzzleHttp\Client;
public function fetchPosts () {
$client = new Client();
$posts = [];
for ($i=1; $i < 2000; $i++) {
$response = $client->post('https://jsonplaceholder.typicode.com/posts/' . $i);
array_push($posts, $response->getBody());
}
return $posts;
}