Skip to content

Commit

Permalink
Merge pull request #104 from mishan/improve-curl-version-compare
Browse files Browse the repository at this point in the history
Use cURL's version_number
  • Loading branch information
rmccue committed Mar 23, 2014
2 parents 5c54aaa + e186156 commit 83508b9
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions library/Requests/Transport/cURL.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
* @subpackage Transport
*/
class Requests_Transport_cURL implements Requests_Transport {
const CURL_7_10_5 = 0x070A05;
const CURL_7_16_2 = 0x071002;

/**
* Raw HTTP data
*
Expand All @@ -30,7 +33,7 @@ class Requests_Transport_cURL implements Requests_Transport {
/**
* Version string
*
* @var string
* @var long
*/
public $version;

Expand Down Expand Up @@ -60,12 +63,12 @@ class Requests_Transport_cURL implements Requests_Transport {
*/
public function __construct() {
$curl = curl_version();
$this->version = $curl['version'];
$this->version = $curl['version_number'];
$this->fp = curl_init();

curl_setopt($this->fp, CURLOPT_HEADER, false);
curl_setopt($this->fp, CURLOPT_RETURNTRANSFER, 1);
if (version_compare($this->version, '7.10.5', '>=')) {
if ($this->version >= self::CURL_7_10_5) {
curl_setopt($this->fp, CURLOPT_ENCODING, '');
}
if (defined('CURLOPT_PROTOCOLS')) {
Expand Down Expand Up @@ -249,12 +252,12 @@ protected function setup_handle($url, $headers, $data, $options) {
break;
}

if( is_int($options['timeout']) or version_compare($this->version, '7.16.2', '<') ) {
if( is_int($options['timeout']) or $this->version < self::CURL_7_16_2 ) {
curl_setopt($this->fp, CURLOPT_TIMEOUT, ceil($options['timeout']));
} else {
curl_setopt($this->fp, CURLOPT_TIMEOUT_MS, round($options['timeout'] * 1000) );
}
if( is_int($options['connect_timeout']) or version_compare($this->version, '7.16.2', '<') ) {
if( is_int($options['connect_timeout']) or $this->version < self::CURL_7_16_2 ) {
curl_setopt($this->fp, CURLOPT_CONNECTTIMEOUT, ceil($options['connect_timeout']));
} else {
curl_setopt($this->fp, CURLOPT_CONNECTTIMEOUT_MS, round($options['connect_timeout'] * 1000));
Expand Down

0 comments on commit 83508b9

Please sign in to comment.