title: Google place API Requesting multiple details JSON pages
body: <p>In my PHP app I currently have two classes, one that can search nearby results from the google places api, and one that can get details from api place references. </p>
  
  <p>I am returning twenty results from a  nearbysearch to the google places api and then looping over the results and passing each reference into the class that gets the place details api response.</p>
  
  <p>The problem I'm having is it is very slow, is there any way of speeding up this process, maybe with concurrent requests to the api?</p>
  
  <pre><code>foreach($results['results'] as $result) {
      $namenospace = str_replace(' ', '_', $result['name']);
          $details = new placedetail($apiKey, $result['reference']);
          $placedetails = $details-&gt;getdetails();
  
          if($placedetails['result']['website']) {
              $website = $placedetails['result']['website'];
              $name = '&lt;a href="'.$website.'" &gt;'.$result['name'].'&lt;/a&gt;';
          } else {
              $name =     $result['name'];
          }
          $html .= '&lt;li class="restaurantoption dontsplit"&gt;';
          $html .=     '&lt;input type="checkbox" class="restaurantcheckbox" name="restaurant[]" value="'.$result['name'].'" checked /&gt;&lt;span class="resaurantname" &gt;'.$name.'&lt;/span&gt;&lt;br/&gt;';
          $html .= '&lt;div class="vicinity" &gt;&lt;small&gt;'.$result['vicinity'].'&lt;/small&gt;&lt;/div&gt;';
          $html .= '&lt;/li&gt;';
  
  }
  
      echo $html;
  
  
  class GooglePlaces {
  
      private $_apiKey;
      public $errors = array();
      public $outputType = "json";
  
      private $_apiUrl = "https://maps.googleapis.com/maps/api/place";
      private $_query;
      private $_address;
      private $_apiCallType = "nearbysearch";
      private $_location;//REQUIRED  - This must be provided as lat,lng
      private $_radius;//REQUIRED
      private $_types;//optional
      private $sensor = 'false'; //REQUIRED
      private $_nextpage;
  
      public function __construct($_apiKey) {
         $this-&gt;_apiKey = $_apiKey;
      }
  
      public function SetLocation($_location) {
         $this-&gt;_location = $_location;
      }
  
      public function setApiUrl($_apiUrl) {
          $this-&gt;_apiUrl = $_apiUrl;  
      }
  
      public function SetRadius($_radius){
         $this-&gt;_radius = $_radius;
      }
  
       public function setNextPage ($_nextpage) {
          $this-&gt;_nextpage = $_nextpage;  
       }   
  
       public function setAddress($_address){
         $this-&gt;_address = $_address;
      }
  
       public function setSearchType($_apiCallType) {
          $this-&gt;_apiCallType = $_apiCallType;    
       }
      public function setQuery($_query) {
          $this-&gt;_query = $_query;    
      } 
      public function SetTypes($_types) {
         $this-&gt;_types = $_types;
      }
      public function getErrors() {
   return $this-&gt;errors;
      }
  
      public function searchPlaces() {
         $URLparams = "location=".$this-&gt;_location."&amp;types=".$this-&gt;_types."&amp;sensor=".$this-&gt;sensor."&amp;rankby=distance";
         $URLToCall = $this-&gt;_apiUrl."/".$this-&gt;_apiCallType."/".$this-&gt;outputType."?key=".$this-&gt;_apiKey."&amp;".$URLparams;
         $result = json_decode(file_get_contents($URLToCall),true);
         if($result['status'] == "OK") {
           return $result;
              } else { 
     $result['status'] = $this-&gt;errors;
    }
   }
  
      public function textsearchPlaces() {
  
               $URLparams = "&amp;types=".$this-&gt;_types."&amp;sensor=".$this-&gt;sensor."&amp;query=".$this-&gt;_query."&amp;rankby=distance";     
         $URLToCall = $this-&gt;_apiUrl."/".$this-&gt;_apiCallType."/".$this-&gt;outputType."?key=".$this-&gt;_apiKey."&amp;".$URLparams;
         $result = json_decode(file_get_contents($URLToCall),true);
         if($result['status'] == "OK") {
           return $result;
           } else {
             $result['status'] = $this-&gt;errors;
           }
      }
  
    public function geocodeResult() {
          $URLparams = "address=".$this-&gt;_address."&amp;sensor=".$this-&gt;sensor;  
         $URLToCall = $this-&gt;_apiUrl."/".$this-&gt;_apiCallType."/".$this-&gt;outputType."?".$URLparams;
         $URLToCall = str_replace(' ', '_', $URLToCall);
         $result = json_decode(file_get_contents($URLToCall), true);
  
           return $result;
  
  
  }
  
  public function loadmore() {
           $URLparams = "sensor=false&amp;pagetoken=".trim($this-&gt;_nextpage);     
         $URLToCall = $this-&gt;_apiUrl."/".$this-&gt;_apiCallType."/".$this-&gt;outputType."?key=".$this-&gt;_apiKey."&amp;".$URLparams;
         $result = json_decode(file_get_contents($URLToCall),true);
         if($result['status'] == "OK") { 
           return $result;
  
           } else {
             $result['status'] = $this-&gt;errors;
  }
  }
  }
  
  
  class placedetail {
      private $_key;
      private $_reference;
      private $_url = 'https://maps.googleapis.com/maps/api/place/details/json';
  
      public function __construct($_key, $_reference) {
         $this-&gt;_key = $_key;
         $this-&gt;_reference = $_reference; 
      }
  
      public function getdetails() {
  
         $URLparams = "reference=".$this-&gt;_reference."&amp;sensor=false";
         $URLToCall = $this-&gt;_url."?key=".$this-&gt;_key."&amp;".$URLparams;
         $result = json_decode(file_get_contents($URLToCall),true);
         if($result['status'] == "OK") {
           return $result;
          } else { 
              $result['status'] = $this-&gt;errors;
          }
      }
  
  
  
  }
  </code></pre>