From 5d4e0d501abd2e3d01965ab89fa010bddee66606 Mon Sep 17 00:00:00 2001 From: php-curl-class Date: Thu, 22 Aug 2013 15:59:47 -0700 Subject: [PATCH] Separate curl error and curl error code from http error and http error code --- Curl.class.php | 11 ++++++++--- tests/run.php | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Curl.class.php b/Curl.class.php index 5639fdf..04ae0c9 100644 --- a/Curl.class.php +++ b/Curl.class.php @@ -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; } diff --git a/tests/run.php b/tests/run.php index 98f9874..a626daf 100644 --- a/tests/run.php +++ b/tests/run.php @@ -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() {