title: Instagram API access rate limit information with specific PHP Class
body: <p>I am using this PHP Class for Instagram's API: <a href="https://github.com/cosenary/Instagram-PHP-API" rel="nofollow noreferrer">https://github.com/cosenary/Instagram-PHP-API</a>.
  It works perfectly but I can't seem to access the rate limit information for each call I make.</p>
  
  <p>Inside the class, this is the method that makes the call:</p>
  
  <pre><code>protected function _makeCall($function, $auth = false, $params = null, $method = 'GET') {
          if (false === $auth) {
              $authMethod = '?client_id=' . $this-&gt;getApiKey();
          } else {
              if (true === isset($this-&gt;_accesstoken)) {
                  $authMethod = '?access_token=' . $this-&gt;getAccessToken();
              } else {
                  throw new \Exception("Error: _makeCall() | $function - This method requires an authenticated users access token.");
              }
          }
  
          if (isset($params) &amp;&amp; is_array($params)) {
              $paramString = '&amp;' . http_build_query($params);
          } else {
              $paramString = null;
          }
  
          $apiCall = self::API_URL . $function . $authMethod . (('GET' === $method) ? $paramString : null);
  
          $headerData = array('Accept: application/json');
          if (true === $this-&gt;_signedheader &amp;&amp; 'GET' !== $method) {
              $headerData[] = 'X-Insta-Forwarded-For: ' . $this-&gt;_signHeader();
          }
  
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL, $apiCall);
          curl_setopt($ch, CURLOPT_HTTPHEADER, $headerData);
          curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  
          if ('POST' === $method) {
              curl_setopt($ch, CURLOPT_POST, count($params));
              curl_setopt($ch, CURLOPT_POSTFIELDS, ltrim($paramString, '&amp;'));
          } else if ('DELETE' === $method) {
              curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
          }
  
          $jsonData = curl_exec($ch);
  
          if (false === $jsonData) {
              throw new \Exception("Error: _makeCall() - cURL error: " . curl_error($ch));
          }
  
          curl_close($ch);
          return json_decode($jsonData);
      }
  </code></pre>
  
  <p>The information I need to access from Instagram's API is:</p>
  
  <blockquote>
    <ul>
    <li>X-Ratelimit-Limit</li>
    <li>X-Ratelimit-Remaining</li>
    </ul>
  </blockquote>
  
  <p>(<a href="http://instagram.com/developer/limits/" rel="nofollow noreferrer">http://instagram.com/developer/limits/</a> for more information about Instagram's limits).</p>
  
  <p>For obvious reasons I need the app I'm creating to "shut itself down" before the rate limit kicks in. By accessing the rate limit information I can achieve this.</p>
  
  <p>I have found a Gist that should work with this class but I can't seem to get it to work: <a href="https://gist.github.com/cosenary/6af4cf4b509518169b88" rel="nofollow noreferrer">https://gist.github.com/cosenary/6af4cf4b509518169b88</a></p>
  
  <p>Also this topic here on Stackoverflow seems to be fruitless:
  <a href="https://stackoverflow.com/questions/12144986/instagram-api-count-limits-using-http-header">Instagram API count limits using HTTP header</a></p>
  
  <p>If anyone could help me out here that would be amazing!</p>
  
  <p>Best regards,
  Peter de Leeuw</p>