Separate curl error and curl error code from http error and http error code

This commit is contained in:
php-curl-class
2013-08-22 15:59:47 -07:00
parent 9ac87e0b19
commit 5d4e0d501a
2 changed files with 9 additions and 4 deletions
+8 -3
View File
@@ -83,9 +83,13 @@ class Curl {
function _exec() {
$this->response = curl_exec($this->curl);
$this->error_code = curl_errno($this->curl);
$this->error_message = curl_error($this->curl);
$this->error = !($this->error_code === 0);
$this->curl_error_code = curl_errno($this->curl);
$this->curl_error_message = curl_error($this->curl);
$this->curl_error = !($this->curl_error_code === 0);
$this->http_error_code = curl_getinfo($this->curl, CURLINFO_HTTP_CODE);
$this->http_error = in_array(floor($this->http_error_code / 100), array(4, 5));
$this->error = $this->curl_error || $this->http_error;
$this->request_headers = preg_split('/\r\n/', curl_getinfo($this->curl, CURLINFO_HEADER_OUT), NULL, PREG_SPLIT_NO_EMPTY);
$this->response_headers = '';
if (!(strpos($this->response, "\r\n\r\n") === FALSE)) {
@@ -96,6 +100,7 @@ class Curl {
list($this->response_headers, $this->response) = $parts;
$this->response_headers = preg_split('/\r\n/', $this->response_headers, NULL, PREG_SPLIT_NO_EMPTY);
}
return $this->error_code;
}
+1 -1
View File
@@ -144,7 +144,7 @@ class CurlTest extends PHPUnit_Framework_TestCase {
$test->curl->setOpt(CURLOPT_CONNECTTIMEOUT_MS, 2000);
$test->curl->get('http://1.2.3.4/');
$this->assertTrue($test->curl->error === TRUE);
$this->assertTrue($test->curl->error_code === CURLE_OPERATION_TIMEOUTED);
$this->assertTrue($test->curl->curl_error_code === CURLE_OPERATION_TIMEOUTED);
}
public function testHeaders() {