ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilCurlConnection Class Reference
+ Collaboration diagram for ilCurlConnection:

Public Member Functions

 __construct ($a_url='')
 Constructor. More...
 
 getResponseHeader ()
 Get response header as string. More...
 
 getResponseHeaderArray ()
 Get response header as array. More...
 
 init (bool $set_proxy=true)
 Init curl connection. More...
 
 setOpt ($a_option, $a_value)
 Wrapper for curl_setopt. More...
 
 exec ()
 Wrapper for curl_exec. More...
 
 parseResponse ($a_response)
 parse response body More...
 
 getResponseBody ()
 Get responce body. More...
 
 getInfo ($opt=0)
 Get informations about a specific transfer. More...
 
 close ()
 Close connection. More...
 
 __destruct ()
 Destructor @access public. More...
 

Static Public Member Functions

static _isCurlExtensionLoaded ()
 Check if curl extension is loaded. More...
 

Protected Attributes

 $url = ''
 
 $ch = null
 

Private Member Functions

 parseHeader ($handle, $header)
 Parse respone header. More...
 

Private Attributes

 $header_plain = ''
 
 $header_arr = array()
 
 $response_body = ''
 

Detailed Description

Definition at line 38 of file class.ilCurlConnection.php.

Constructor & Destructor Documentation

◆ __construct()

ilCurlConnection::__construct (   $a_url = '')

Constructor.

@access public

Parameters
stringurl for connection
Exceptions
ilCurlConnectionException

Definition at line 56 of file class.ilCurlConnection.php.

57 {
58 $this->url = $a_url;
59
60 if (!self::_isCurlExtensionLoaded()) {
61 throw new ilCurlConnectionException('Curl extension not enabled.');
62 }
63 }

◆ __destruct()

ilCurlConnection::__destruct ( )

Destructor @access public.

Parameters

Definition at line 259 of file class.ilCurlConnection.php.

260 {
261 $this->close();
262 }
close()
Close connection.

References close().

+ Here is the call graph for this function:

Member Function Documentation

◆ _isCurlExtensionLoaded()

static ilCurlConnection::_isCurlExtensionLoaded ( )
staticfinal

Check if curl extension is loaded.

@access public

Definition at line 72 of file class.ilCurlConnection.php.

73 {
74 if (!function_exists('curl_init')) {
75 return false;
76 }
77 return true;
78 }

Referenced by ilLinkChecker\__validateLinks(), ilNICKeyRegisteredObjective\achieve(), ilMediaImageUtil\getImageSize(), and ilClient\updateNIC().

+ Here is the caller graph for this function:

◆ close()

ilCurlConnection::close ( )
final

Close connection.

@access public

Definition at line 246 of file class.ilCurlConnection.php.

247 {
248 if ($this->ch != null) {
249 curl_close($this->ch);
250 $this->ch = null;
251 }
252 }

Referenced by __destruct(), and init().

+ Here is the caller graph for this function:

◆ exec()

ilCurlConnection::exec ( )
final

Wrapper for curl_exec.

@access public

Parameters

Definition at line 169 of file class.ilCurlConnection.php.

170 {
171 // Add header function
172 curl_setopt($this->ch, CURLOPT_HEADERFUNCTION, array($this,'parseHeader'));
173 if ((@$res = curl_exec($this->ch)) === false) {
174 if (strlen($err = curl_error($this->ch))) {
175 throw new ilCurlConnectionException($err, curl_errno($this->ch));
176 } else {
177 throw new ilCurlConnectionException('Error calling curl_exec().');
178 }
179 }
180 return $res;
181 }
foreach($_POST as $key=> $value) $res

References $res.

◆ getInfo()

ilCurlConnection::getInfo (   $opt = 0)

Get informations about a specific transfer.

@access public

Parameters
intoption e.g CURLINFO_EFFECTIVE_URL
Returns
mixed

Definition at line 212 of file class.ilCurlConnection.php.

213 {
214 if ($opt) {
215 $res = curl_getinfo($this->ch, $opt);
216 } else {
217 $res = curl_getinfo($this->ch);
218 }
219 return $res;
220 }

References $res.

Referenced by parseResponse().

+ Here is the caller graph for this function:

◆ getResponseBody()

ilCurlConnection::getResponseBody ( )

Get responce body.

Returns
type

Definition at line 199 of file class.ilCurlConnection.php.

References $response_body.

◆ getResponseHeader()

ilCurlConnection::getResponseHeader ( )

Get response header as string.

Returns
string

Definition at line 84 of file class.ilCurlConnection.php.

References $header_plain.

Referenced by parseHeader().

+ Here is the caller graph for this function:

◆ getResponseHeaderArray()

ilCurlConnection::getResponseHeaderArray ( )

Get response header as array.

Returns
array

Definition at line 93 of file class.ilCurlConnection.php.

94 {
95 return (array) $this->header_arr;
96 }

References $header_arr.

◆ init()

ilCurlConnection::init ( bool  $set_proxy = true)
final

Init curl connection.

Parameters
bool$set_proxy

@access public

Exceptions
ilCurlConnectionExceptionon error

Definition at line 107 of file class.ilCurlConnection.php.

108 {
109 // teminate existing handles
110 $this->close();
111 if (strlen($this->url)) {
112 $this->ch = curl_init($this->url);
113 #$GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': ' . $this->url);
114 } else {
115 $this->ch = curl_init();
116 }
117 if (!$this->ch) {
118 throw new ilCurlConnectionException('Cannot init curl connection.');
119 }
120 if (curl_errno($this->ch)) {
121 throw new ilCurlConnectionException(curl_error($this->ch), curl_errno($this->ch));
122 }
123
124 if ($set_proxy) {
125 // use a proxy, if configured by ILIAS
127 if ($proxy->isActive()) {
128 $this->setOpt(CURLOPT_HTTPPROXYTUNNEL, true);
129
130 if (!empty($proxy->getHost())) {
131 $this->setOpt(CURLOPT_PROXY, $proxy->getHost());
132 } else {
133 throw new ilCurlConnectionException("Proxy host is not set on activated proxy");
134 }
135
136 if (!empty($proxy->getPort())) {
137 $this->setOpt(CURLOPT_PROXYPORT, $proxy->getPort());
138 }
139 }
140 }
141
142 return true;
143 }
setOpt($a_option, $a_value)
Wrapper for curl_setopt.
static _getInstance()
Getter for unique instance.

References ilProxySettings\_getInstance(), close(), and setOpt().

+ Here is the call graph for this function:

◆ parseHeader()

ilCurlConnection::parseHeader (   $handle,
  $header 
)
private

Parse respone header.

Parameters
mixed$handle
string$header
Returns
int strlen of header

Definition at line 228 of file class.ilCurlConnection.php.

229 {
230 $this->header_plain = $header;
231
232 $lines = explode('\r\n', $this->getResponseHeader());
233 foreach ($lines as $line) {
234 list($name, $value) = explode(':', $line, 2);
235 $this->header_arr[$name] = $value;
236 }
237 return strlen($this->getResponseHeader());
238 }
getResponseHeader()
Get response header as string.
if($format !==null) $name
Definition: metadata.php:230

References $name, and getResponseHeader().

+ Here is the call graph for this function:

◆ parseResponse()

ilCurlConnection::parseResponse (   $a_response)

parse response body

Parameters
type$a_response

Definition at line 187 of file class.ilCurlConnection.php.

188 {
189 $header_size = $this->getInfo(CURLINFO_HEADER_SIZE);
190
191 $this->header_plain = substr($a_response, 0, $header_size);
192 $this->response_body = substr($a_response, $header_size);
193 }
getInfo($opt=0)
Get informations about a specific transfer.

References getInfo().

+ Here is the call graph for this function:

◆ setOpt()

ilCurlConnection::setOpt (   $a_option,
  $a_value 
)
final

Wrapper for curl_setopt.

@access public

Parameters
intCURL_OPTION
mixedbool string or resource
Exceptions
ilCurlConnectionExceptionon error

Definition at line 154 of file class.ilCurlConnection.php.

155 {
156 if (!@curl_setopt($this->ch, $a_option, $a_value)) {
157 throw new ilCurlConnectionException('Invalid option given for: ' . $a_option, curl_errno($this->ch));
158 }
159 return true;
160 }

Referenced by init().

+ Here is the caller graph for this function:

Field Documentation

◆ $ch

ilCurlConnection::$ch = null
protected

Definition at line 41 of file class.ilCurlConnection.php.

◆ $header_arr

ilCurlConnection::$header_arr = array()
private

Definition at line 44 of file class.ilCurlConnection.php.

Referenced by getResponseHeaderArray().

◆ $header_plain

ilCurlConnection::$header_plain = ''
private

Definition at line 43 of file class.ilCurlConnection.php.

Referenced by getResponseHeader().

◆ $response_body

ilCurlConnection::$response_body = ''
private

Definition at line 46 of file class.ilCurlConnection.php.

Referenced by getResponseBody().

◆ $url

ilCurlConnection::$url = ''
protected

Definition at line 40 of file class.ilCurlConnection.php.


The documentation for this class was generated from the following file: