Skip to content

Commit cf7a203

Browse files
Gnilyastevenbrookes
authored andcommitted
Check for 429 and sleep
1 parent 52cfe7d commit cf7a203

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
vendor
2+
/nbproject/private/

lib/CurlRequest.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,24 @@ public static function delete($url, $httpHeaders = array())
140140
*/
141141
protected static function processRequest($ch)
142142
{
143-
// $output contains the output string
144-
$output = curl_exec($ch);
145-
143+
# Check for 429 leaky bucket error
144+
while(1) {
145+
$output = curl_exec($ch);
146+
self::$lastHttpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
147+
if(self::$lastHttpCode != 429) {
148+
break;
149+
}
150+
usleep(500000);
151+
}
152+
146153
if (curl_errno($ch)) {
147154
throw new Exception\CurlException(curl_errno($ch) . ' : ' . curl_error($ch));
148155
}
149156

150-
self::$lastHttpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
151-
152157
// close curl resource to free up system resources
153158
curl_close($ch);
154159

155160
return $output;
156161
}
162+
157163
}

lib/HttpRequestJson.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public static function get($url, $httpHeaders = array())
6868
{
6969
self::prepareRequest($httpHeaders);
7070

71-
ShopifySDK::checkApiCallLimit();
7271
$response = CurlRequest::get($url, self::$httpHeaders);
7372

7473
return self::processResponse($response);
@@ -87,7 +86,6 @@ public static function post($url, $dataArray, $httpHeaders = array())
8786
{
8887
self::prepareRequest($httpHeaders, $dataArray);
8988

90-
ShopifySDK::checkApiCallLimit();
9189
$response = CurlRequest::post($url, self::$postDataJSON, self::$httpHeaders);
9290

9391
return self::processResponse($response);
@@ -106,7 +104,6 @@ public static function put($url, $dataArray, $httpHeaders = array())
106104
{
107105
self::prepareRequest($httpHeaders, $dataArray);
108106

109-
ShopifySDK::checkApiCallLimit();
110107
$response = CurlRequest::put($url, self::$postDataJSON, self::$httpHeaders);
111108

112109
return self::processResponse($response);
@@ -124,7 +121,6 @@ public static function delete($url, $httpHeaders = array())
124121
{
125122
self::prepareRequest($httpHeaders);
126123

127-
ShopifySDK::checkApiCallLimit();
128124
$response = CurlRequest::delete($url, self::$httpHeaders);
129125

130126
return self::processResponse($response);

0 commit comments

Comments
 (0)