8000 Merge pull request #39 from finwe/timeouts · devildeveloper/codebird-php@85885c7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 85885c7

Browse files
committed
Merge pull request jublo#39 from finwe/timeouts
Availability to set cURL timeouts
2 parents 3cbae77 + 447016d commit 85885c7

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

‎ 10000 src/codebird.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ class Codebird
109109
*/
110110
protected $_version = '2.4.2-dev';
111111

112+
/**
113+
* Request timeout
114+
*/
115+
protected $_timeout;
116+
117+
/**
118+
* Connection timeout
119+
*/
120+
protected $_connectionTimeout;
121+
112122
/**
113123
* Returns singleton class instance
114124
* Always use this method unless you're working with multiple authenticated users at once
@@ -173,6 +183,30 @@ public function setToken($token, $secret)
173183
$this->_oauth_token_secret = $secret;
174184
}
175185

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+
176210
/**
177211
* Sets the format for API replies
178212
*
@@ -905,6 +939,14 @@ protected function _callApi($httpmethod, $method, $method_template, $params = ar
905939
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
906940
curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . '/cacert.pem');
907941

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+
908950
$reply = curl_exec($ch);
909951

910952
// certificate validation results

0 commit comments

Comments
 (0)
0