@@ -71,7 +71,7 @@ public static function get($url, $httpHeaders = array())
71
71
//Initialize the Curl resource
72
72
$ ch = self ::init ($ url , $ httpHeaders );
73
73
74
- return self ::processRequest ($ ch );
74
+ return self ::processRequest ($ ch, $ url );
75
75
}
76
76
77
77
/**
@@ -90,7 +90,7 @@ public static function post($url, $data, $httpHeaders = array())
90
90
curl_setopt ($ ch , CURLOPT_CUSTOMREQUEST , 'POST ' );
91
91
curl_setopt ($ ch , CURLOPT_POSTFIELDS , $ data );
92
92
93
- return self ::processRequest ($ ch );
93
+ return self ::processRequest ($ ch, $ url );
94
94
}
95
95
96
96
/**
@@ -109,7 +109,7 @@ public static function put($url, $data, $httpHeaders = array())
109
109
curl_setopt ($ ch , CURLOPT_CUSTOMREQUEST , 'PUT ' );
110
110
curl_setopt ($ ch , CURLOPT_POSTFIELDS , $ data );
111
111
112
- return self ::processRequest ($ ch );
112
+ return self ::processRequest ($ ch, $ url );
113
113
}
114
114
115
115
/**
@@ -126,7 +126,7 @@ public static function delete($url, $httpHeaders = array())
126
126
//set the request type
127
127
curl_setopt ($ ch , CURLOPT_CUSTOMREQUEST , 'DELETE ' );
128
128
129
- return self ::processRequest ($ ch );
129
+ return self ::processRequest ($ ch, $ url );
130
130
}
131
131
132
132
/**
@@ -138,18 +138,32 @@ public static function delete($url, $httpHeaders = array())
138
138
*
139
139
* @return string
140
140
*/
141
- protected static function processRequest ($ ch )
141
+ protected static function processRequest ($ ch, $ url )
142
142
{
143
- $ output = curl_exec ($ ch );
144
- self ::$ lastHttpCode = curl_getinfo ($ ch , CURLINFO_HTTP_CODE );
143
+ $ split = parse_url ($ url );
144
+ $ host = $ split ['host ' ];
145
+
146
+ $ output = null ;
147
+ while (1 ) {
148
+ Redis::throttle ($ host )->allow (2 )->every (1 )->then (function () use (&$ ch , &$ output ) {
149
+ $ output = curl_exec ($ ch );
150
+ self ::$ lastHttpCode = curl_getinfo ($ ch , CURLINFO_HTTP_CODE );
151
+ },
152
+
153
+ function () {
154
+ });
155
+
156
+ if (isset ($ output )) {
157
+ break ;
158
+ }
159
+ }
145
160
146
161
if (curl_errno ($ ch )) {
147
162
throw new Exception \CurlException (curl_errno ($ ch ) . ' : ' . curl_error ($ ch ));
148
163
}
149
164
150
165
// close curl resource to free up system resources
151
166
curl_close ($ ch );
152
-
153
167
return $ output ;
154
168
}
155
169
0 commit comments