1

I currently have a PHP function which makes a GET request to Google Places API in order to get the details for a place based on the id of that place.

public function getSight(Request $request, $placeid) {
    $get = file_get_contents("https://maps.googleapis.com/maps/api/place/details/json?placeid=" . $placeid . "&key=");
    $result = json_decode($get);

    return response()->json([
        'message' => 'Fetched sight!',
        'result' => $result
    ], 201);
}

This is all good and dandy, however, now I want to expand the functionality of my application by allowing users to save the IDs of places they like in the database and then display all liked places on a certain page. Does this mean I'd have to literally run 10 GET requests if the user has liked 10 places? Would that be extremely slow, especially if the user has like 20, 30 or 100 places? I'm reading the Google Places API documentation and I can't find any information about getting more than 1 place details using a single GET request.

Surely there's a better way for me to accomplish this.

Onyx
  • 5,186
  • 8
  • 39
  • 86
  • try looking at making concurrent http GET requests through cURL https://stackoverflow.com/q/9308779/7316335 – Loveen Dyall Apr 14 '19 at 22:30
  • "extremely" and "slow" are subjective. Why don't you actually measure the performance but running request for 100 pages. As suggested above, you can run multiple requests in parallel. Or you can run the requests asynchronously. Do different users share liked places? You can cache the results of the requests. – Dr Phil Apr 14 '19 at 23:46

0 Answers0