title: Facebook PHP SDK "Too many requests in batch message. Maximum batch size is 50"
body: <p>I'm trying to get the profiles of a large group of friends and I'm getting the error:</p>
  
  <pre><code>Too many requests in batch message. Maximum batch size is 50
  </code></pre>
  
  <p>From the API. Now I understand the error message but I thought I built the function to mitigate this error. I specifically make the calls in chunks of 50. I don't change $chunk_size in any of the methods that call it so I don't really know what is going on here.</p>
  
  <p>This is the function that is spitting out the error:</p>
  
  <pre><code>protected function getFacebookProfiles($ids, array $fields = array('name', 'picture'), $chunk_size = 50)
  {
      $facebook = App::make('Facebook');
      $fields = implode(',', $fields);
  
      $requests = array();
      foreach ($ids as $id) {
          $requests[] = array('method' =&gt; 'GET', 'relative_url' =&gt; "{$id}?fields={$fields}");
      }
  
      $responses = array();
      $chunks = array_chunk($requests, $chunk_size);
      foreach ($chunks as $chunk) {
          $batch = json_encode($requests);
          $response = $facebook-&gt;api("?batch={$batch}", 'POST');
  
          foreach ($response as &amp;$profile) {
              $profile = json_decode($profile['body']);
  
              if (empty($profile-&gt;picture-&gt;data)) {
                  // something has gone REALLY wrong, this should never happen but if it does we'll have more debug information
                  if (empty($profile-&gt;error-&gt;message)) {
                      throw new Exception('Unexpected error when retrieving user information for IDs:' . implode(', ', $ids));
                  }
  
                  $profile-&gt;error = (array) $profile-&gt;error;
                  throw new FacebookApiException((array) $profile);
              }
  
              $profile-&gt;picture = $profile-&gt;picture-&gt;data;
          }
  
          $responses = array_merge($responses, $response);
      }
  
      return $responses;
  }
  </code></pre>