I have an application that performs a GET request to a REST API endpoint to retrieve a list of posts. The response returns a list of posts, however does not include all the fields necessary. Because of this, I have to do another GET request to a different endpoint to retrieve all fields of a given post, this call is inside a loop.
$posts = $client->getPosts(); // Get list of posts
foreach ( (array) $posts as $post ) {
$post = $client->getPost( $post->postID ); // Get more information for this post
// Do something
}
Obviously the issue with this is if the initial request returns a large list, the application will timeout during the loop. I'm looking for a better way to break this up to prevent timing out and successfully complete all the API requests. The caveat is this script runs on a CRON schedule so I think we cannot do this using JS.
Any help is much appreciated in advance