diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index 53a257d..5b0b7b0 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -56,7 +56,6 @@ class Curl public $httpStatusCode = 0; public $httpErrorMessage = null; - public $totalTime = 0; public $baseUrl = null; public $url = null; public $effectiveUrl = null; @@ -82,6 +81,10 @@ class Curl private $xmlDecoder = null; private $xmlPattern = '~^(?:text/|application/(?:atom\+|rss\+)?)xml~i'; + private static $deferredProperties = array( + 'totalTime', + ); + /** * Construct * @@ -348,7 +351,6 @@ class Curl $this->curlErrorMessage = curl_error($this->curl); $this->curlError = !($this->curlErrorCode === 0); $this->httpStatusCode = curl_getinfo($this->curl, CURLINFO_HTTP_CODE); - $this->totalTime = curl_getinfo($this->curl, CURLINFO_TOTAL_TIME); $this->httpError = in_array(floor($this->httpStatusCode / 100), array(4, 5)); $this->error = $this->curlError || $this->httpError; $this->errorCode = $this->error ? ($this->curlError ? $this->curlErrorCode : $this->httpStatusCode) : 0; @@ -953,6 +955,19 @@ class Curl $this->close(); } + public function __get($name) + { + $return = null; + if (in_array($name, self::$deferredProperties) && is_callable(array($this, $getter = '__get_' . $name))) { + $return = $this->$name = $this->$getter(); + } + return $return; + } + + private function __get_totalTime() { + return curl_getinfo($this->curl, CURLINFO_TOTAL_TIME); + } + /** * Build Url * diff --git a/tests/PHPCurlClass/PHPCurlClassTest.php b/tests/PHPCurlClass/PHPCurlClassTest.php index 6d46296..0e38938 100644 --- a/tests/PHPCurlClass/PHPCurlClassTest.php +++ b/tests/PHPCurlClass/PHPCurlClassTest.php @@ -2650,4 +2650,11 @@ class CurlTest extends PHPUnit_Framework_TestCase $test->server('xml_with_cdata_response', 'POST', $data); $this->assertTrue(strpos($test->curl->response->saveXML(), 'server('request_method', 'GET'); + $this->assertTrue(is_float($test->curl->totalTime)); + } }