@@ -109,6 +109,16 @@ class Codebird
109
109
*/
110
110
protected $ _version = '2.4.2-dev ' ;
111
111
112
+ /**
113
+ * Request timeout
114
+ */
115
+ protected $ _timeout ;
116
+
117
+ /**
118
+ * Connection timeout
119
+ */
120
+ protected $ _connectionTimeout ;
121
+
112
122
/**
113
123
* Returns singleton class instance
114
124
* Always use this method unless you're working with multiple authenticated users at once
@@ -173,6 +183,30 @@ public function setToken($token, $secret)
173
183
$ this ->_oauth_token_secret = $ secret ;
174
184
}
175
185
186
+ /**
187
+ * Sets request timeout in milliseconds
188
+ *
189
+ * @param int $timeout Request timeout in milliseconds
190
+ *
191
+ * @return void
192
+ */
193
+ public function setTimeout ($ timeout )
194
+ {
195
+ $ this ->_timeout = (int ) $ timeout ;
196
+ }
197
+
198
+ /**
199
+ * Sets connection timeout in milliseconds
200
+ *
201
+ * @param int $timeout Connection timeout in milliseconds
202
+ *
203
+ * @return void
204
+ */
205
+ public function setConnectionTimeout ($ timeout )
206
+ {
207
+ $ this ->_connectionTimeout = (int ) $ timeout ;
208
+ }
209
+
176
210
/**
177
211
* Sets the format for API replies
178
212
*
@@ -905,6 +939,14 @@ protected function _callApi($httpmethod, $method, $method_template, $params = ar
905
939
curl_setopt ($ ch , CURLOPT_SSL_VERIFYHOST , 2 );
906
940
curl_setopt ($ ch , CURLOPT_CAINFO , __DIR__ . '/cacert.pem ' );
907
941
942
+ if (isset ($ this ->_timeout )) {
943
+ curl_setopt ($ ch , CURLOPT_TIMEOUT_MS , $ this ->_timeout );
944
+ }
945
+
946
+ if (isset ($ this ->_connectionTimeout )) {
947
+ curl_setopt ($ ch , CURLOPT_CONNECTTIMEOUT_MS , $ this ->_connectionTimeout );
948
+ }
949
+
908
950
$ reply = curl_exec ($ ch );
909
951
910
952
// certificate validation results
0 commit comments