title: cakephp probleme with pagination and file_get_contents
body: <p>I develop a back-end for a mobile application with cakephp</p>
  
  <p>I have a function that list cities and I want to calculate distance from the user the this cities the code is:</p>
  
  <pre><code>$origins='origins=casablanca,maroc';
      $destinations='&amp;destinations=';
      $url='http://maps.googleapis.com/maps/api/distancematrix/json?';
  
      $this-&gt;paginate = array(
              'limit' =&gt; 10,
              'fields'=&gt;array('cityId','cityFileName','cityName','stateId','stateFileName','stateName',
                  'countryCode','countryFileName','countryName','count(id) as num_hotels'),
              'order' =&gt; 'num_hotels desc',
              'group' =&gt;array('cityId')
  
      );
      $hotels = $this-&gt;paginate();
  
      for ($i = 0; $i &lt; count($hotels); ++$i) {
  
          $destination=($i==0?'':'|');
  
          $destination.=$hotels[$i]['Hotel']['cityName'].','.$hotels[$i]['Hotel']['countryName'];
  
          $destinations.=$destination;
      }
  
      $url.=$origins.$destinations.'&amp;mode=driving&amp;language=fr-FR&amp;sensor=false';
  
      $json = file_get_contents($url,0,null,null);
      $details = json_decode($json, TRUE);
  
      for ($i = 0; $i &lt; count($hotels); ++$i) {
          $hotels = Set::insert($hotels, $i.'.Hotel.distance',$details['rows']['0']['elements']['0']['distance']['value']);
      }
  
      $this-&gt;set(compact('hotels'));
      $this -&gt; viewPath = "hotels";
      $this -&gt; render("json/index","json/default");
  </code></pre>
  
  <p>the problem is when i test with the first page (pagination) the result is good but when i access to others page >=2 i got this warning and i cant get the distance</p>
  
  <p>the error is :</p>
  
  <pre><code>Warning (2): file_get_contents(http://maps.googleapis.com/maps/api/distancematrix/json?origins=casablanca,maroc&amp;destinations=Zagora,Morocco|Meknes,Morocco|Chefchaouen,Morocco|Tinghir,Morocco|M'hamid,Morocco|El Jadida,Morocco|Erfoud,Morocco|Skoura,Morocco|Tetouan,Morocco|Imlil,Morocco&amp;mode=driving&amp;language=fr-FR&amp;sensor=false) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request
  </code></pre>
  
  <p>[APP\Controller\ApiController.php, line 81]</p>
  
  <blockquote>
    <p>Code Context</p>
    
    <p>$origins  =   "origins=casablanca,maroc"
    $destinations =   "&amp;destinations=Zagora,Morocco|Meknes,Morocco|Chefchaouen,Morocco|Tinghir,Morocco|M'hamid,Morocco|El
    Jadida,Morocco|Erfoud,Morocco|Skoura,Morocco|Tetouan,Morocco|Imlil,Morocco"
    $url  =   "<a href="http://maps.googleapis.com/maps/api/distancematrix/json?origins=casablanca,maroc&amp;destinations=Zagora,Morocco|Meknes,Morocco|Chefchaouen,Morocco|Tinghir,Morocco|M" rel="nofollow">http://maps.googleapis.com/maps/api/distancematrix/json?origins=casablanca,maroc&amp;destinations=Zagora,Morocco|Meknes,Morocco|Chefchaouen,Morocco|Tinghir,Morocco|M</a>'hamid,Morocco|El
    Jadida,Morocco|Erfoud,Morocco|Skoura,Morocco|Tetouan,Morocco|Imlil,Morocco&amp;mode=driving&amp;language=fr-FR&amp;sensor=false"
    $hotels   =   array(  array(  "Hotel" => array(),     array() ),  array(
      "Hotel" => array(),     array() ),  array(  "Hotel" => array(),     array()
    ),    array(  "Hotel" => array(),     array() ),  array(  "Hotel" =>
    array(),  array() ),  array(  "Hotel" => array(),     array() ),  array(
      "Hotel" => array(),     array() ),  array(  "Hotel" => array(),     array()
    ),    array(  "Hotel" => array(),     array() ),  array(  "Hotel" =>
    array(),  array() ) ) $i  =   10 $destination =   "|Imlil,Morocco"
    $http_response_header =   array(  "HTTP/1.0 400 Bad Request",
      "Content-Type: text/html; charset=UTF-8",   "Content-Length: 925",
      "Date: Wed, 08 Aug 2012 15:42:43 GMT",  "Server: GFE/2.0" )</p>
    
    <p>file_get_contents - [internal], line ?? ApiController::yassine() -
    APP\Controller\ApiController.php, line 81
    ReflectionMethod::invokeArgs() - [internal], line ??
    Controller::invokeAction() - CORE\Cake\Controller\Controller.php, line
    473 Dispatcher::_invoke() - CORE\Cake\Routing\Dispatcher.php, line 104
    Dispatcher::dispatch() - CORE\Cake\Routing\Dispatcher.php, line 86
    [main] - APP\webroot\index.php, line 96</p>
  </blockquote>