8000 Availability to set cURL timeouts by finwe · Pull Request #39 · jublo/codebird-php · GitHub
[go: up one dir, main page]

Skip to content

Availability to set cURL timeouts #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/codebird.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ class Codebird
*/
protected $_version = '2.4.2-dev';

/**
* Request timeout
*/
protected $_timeout;

/**
* Connection timeout
*/
protected $_connectionTimeout;

/**
* Returns singleton class instance
* Always use this method unless you're working with multiple authenticated users at once
Expand Down Expand Up @@ -173,6 +183,30 @@ public function setToken($token, $secret)
$this->_oauth_token_secret = $secret;
}

/**
* Sets request timeout in milliseconds
*
* @param int $timeout Request timeout in milliseconds
*
* @return void
*/
public function setTimeout($timeout)
{
$this->_timeout = (int) $timeout;
}

/**
* Sets connection timeout in milliseconds
*
* @param int $timeout Connection timeout in milliseconds
*
* @return void
*/
public function setConnectionTimeout($timeout)
{
$this->_connectionTimeout = (int) $timeout;
}

/**
* Sets the format for API replies
*
Expand Down Expand Up @@ -905,6 +939,14 @@ protected function _callApi($httpmethod, $method, $method_template, $params = ar
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . '/cacert.pem');

if (isset($this->_timeout)) {
curl_setopt($ch, CURLOPT_TIMEOUT_MS, $this->_timeout);
}

if (isset($this->_connectionTimeout)) {
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, $this->_connectionTimeout);
}

$reply = curl_exec($ch);

// certificate validation results
Expand Down
0