This repository has been archived by the owner on Jan 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update ActiveResource to handle Status 429 Too Many Requests
- Loading branch information
Showing
1 changed file
with
16 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,8 @@ | |
* ?> | ||
* | ||
* @author John Luxford <[email protected]> | ||
* @version 0.14 beta | ||
* @author Rafael Lima - http://rafael.adm.br | ||
* @version 0.15 beta | ||
* @license http://opensource.org/licenses/lgpl-2.1.php | ||
*/ | ||
class ActiveResource { | ||
|
@@ -635,15 +636,28 @@ function _fetch ($url, $method, $params) { | |
} | ||
$res = curl_exec ($ch); | ||
|
||
// Check HTTP status code for denied access | ||
$http_code = curl_getinfo ($ch, CURLINFO_HTTP_CODE); | ||
|
||
// Check HTTP status code for denied access | ||
if ($http_code == 401) { | ||
$this->errno = $http_code; | ||
$this->error = "HTTP Basic: Access denied."; | ||
curl_close ($ch); | ||
return false; | ||
} | ||
|
||
// Check HTTP status code for rate limit | ||
if ($http_code == 429) { | ||
if (preg_match ('/Retry-After: ([0-9]+)/', $res, $retry_after)) { | ||
sleep(intval($retry_after[1])); | ||
return $this->_fetch ($url, $method, $params); | ||
} | ||
$this->errno = $http_code; | ||
$this->error = "Too Many Requests"; | ||
curl_close ($ch); | ||
return false; | ||
} | ||
|
||
if (! $res) { | ||
$this->errno = curl_errno ($ch); | ||
$this->error = curl_error ($ch); | ||
|