Index: branches/RC/core/units/general/helpers/curl_helper.php =================================================================== diff -u -r8929 -r9308 --- branches/RC/core/units/general/helpers/curl_helper.php (.../curl_helper.php) (revision 8929) +++ branches/RC/core/units/general/helpers/curl_helper.php (.../curl_helper.php) (revision 9308) @@ -1,72 +1,72 @@ debugMode = $this->Application->isDebugMode(false) && constOn('DBG_CURL'); } - + function SetOptions() { // customizable options curl_setopt($this->connectionID, CURLOPT_FOLLOWLOCATION, $this->followLocation ? 1 : 0); curl_setopt($this->connectionID, CURLOPT_TIMEOUT, $this->timeout); - + // hardcoded options curl_setopt($this->connectionID, CURLOPT_RETURNTRANSFER, 1); curl_setopt($this->connectionID, CURLOPT_REFERER, PROTOCOL.SERVER_NAME); curl_setopt($this->connectionID, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); - + if ($this->requestHeaders) { curl_setopt($this->connectionID, CURLOPT_HTTPHEADER, $this->prepareHeaders()); } @@ -103,16 +103,16 @@ curl_setopt($this->connectionID, CURLOPT_POST, 1); curl_setopt($this->connectionID, CURLOPT_POSTFIELDS, $this->postData); } - + // curl_setopt($this->connectionID, CURLOPT_HEADERFUNCTION, Array(&$this, 'ParseHeader')); } - + function ParseHeader(&$ch, $header) { $this->responceHeaders[] = $header; return strlen($header); } - + /** * Sets POST data for next query * @@ -127,20 +127,20 @@ } $post_data = $params_str; } - + $this->postData = $post_data; } - + function SetHeaders($headers) { $this->requestHeaders = array_merge_recursive2($this->requestHeaders, $headers); } - + function SetHeader($name, $value) { $this->requestHeaders[$name] = $value; } - + /** * Returns compiled header to be used by curl * @@ -154,11 +154,11 @@ } return $ret; } - - function Send($url) + + function Send($url, $close_connection = true) { $this->connectionID = curl_init($url); - + if ($this->debugMode) { safeDefine('DBG_CURL_LOGFILE', '/curl.log'); $this->logFilePointer = fopen(FULL_PATH.DBG_CURL_LOGFILE, 'a'); @@ -168,31 +168,53 @@ curl_setopt($this->connectionID, CURLOPT_STDERR, $this->logFilePointer); //curl_setopt($this->connectionID, CURLOPT_WRITEHEADER, $this->logFilePointer); } - + $this->responceHeaders = Array (); - + $this->SetOptions(); $this->lastRespoce = curl_exec($this->connectionID); - $this->Finalize(); - + + $this->Finalize($close_connection); + return $this->lastRespoce; } - - function Finalize() + + /** + * Returns various info about request made + * + * @param int $info_type + * @return mixed + * + * @see http://www.php.net/manual/ru/function.curl-getinfo.php + */ + function getInfo($info_type) { + return curl_getinfo($this->connectionID, $info_type); + } + + function Finalize($close_connection = true) + { $this->lastErrorCode = curl_errno($this->connectionID); $this->lastErrorMsg = curl_error($this->connectionID); $this->lastHTTPCode = curl_getinfo($this->connectionID, CURLINFO_HTTP_CODE); - + if ($this->debugMode) { fwrite($this->logFilePointer, "\n".$this->lastRespoce); fclose($this->logFilePointer); } - - curl_close($this->connectionID); + $this->postData = ''; $this->requestHeaders = Array (); + + if ($close_connection) { + $this->CloseConnection(); + } } + + function CloseConnection() + { + curl_close($this->connectionID); + } } - + ?> \ No newline at end of file