\CommuniqueCurl

cURL Class

This class is used to provide an object wrapper around cURL

Summary

Methods
Properties
Constants
__construct()
__destruct()
__clone()
version()
strerror()
file_create()
errno()
error()
escape()
exec()
getinfo()
pause()
setopt_array()
setopt()
unescape()
reset()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
headers_to_array()
$_ch
N/A

Properties

$_ch

$_ch : Object

A cURL handle created when the object is constructed

Type

Object

Methods

__construct()

__construct(string  $url = null) 

Constructs the cURL object wrapper

Parameters

string $url

If provided, the CURLOPT_URL option will be set to its value. You can manually set this using the setopt() method.

Throws

\Communique\CommuniqueRESTConnectionException

__destruct()

__destruct() 

Called when the object is garbage collected. This method basically just closes the cURL handle.

__clone()

__clone() 

Called when the object is copied using the `clone` operator.

Copies the current cURL handle and sets the value returned from curl_copy_handle() as the value of $this->_ch

version()

version(integer  $age = CURLVERSION_NOW) : array

Gets cURL version information

Parameters

integer $age

Returns

array —

Returns an asociative array with information regarding the version of cURL in question

strerror()

strerror(integer  $errornum) : string

Return string describing the given error code

Parameters

integer $errornum

One of the cURL error codes constants

Returns

string —

Returns error description or NULL for invalid error code.

file_create()

file_create(string  $filename, string  $mimetype = '', string  $postname = '') : \CURLFile

Create a CURLFile object

Parameters

string $filename

Path to the file which will be uploaded

string $mimetype

Mimetype of the file

string $postname

Name of the file to be used in the upload data

Returns

\CURLFile —

Returns a CURLFile object

errno()

errno() : integer

Return the last error number

Returns

integer —

Returns the error number or 0 (zero) if no error ocurred.

error()

error() : string

Return a a string containing the last error for the current session

Returns

string —

Returns the error message or "" (the empty string) if no error ocurred

escape()

escape(string  $str) : string|boolean

URL encodes the given string

Parameters

string $str

The string to be encoded

Returns

string|boolean —

Returns escaped string or FALSE on failiure

exec()

exec() : boolean|mixed

This function should be called after initializing a cURL session and all the options for the session are set

Returns

boolean|mixed —

Returns TRUE on success or FALSE on failiure. However, if the CURLOPT_RETURNTANSFER option is set, it will return the result on success, FALSE on failiure

getinfo()

getinfo(integer  $opt) : mixed|array|boolean

Get information regarding a specific transfer

Parameters

integer $opt

This may be one of the following constants:

  1. CURLINFO_EFFECTIVE_URL - Last effective URL
  2. CURLINFO_HTTP_CODE - Last received HTTP code
  3. CURLINFO_FILETIME - Remote time of the retrieved document, if -1 is returned the time of the document is unknown
  4. CURLINFO_TOTAL_TIME - Total transaction time in seconds for last transfer
  5. CURLINFO_NAMELOOKUP_TIME - Time in seconds until name resolving was complete
  6. CURLINFO_CONNECT_TIME - Time in seconds it took to establish the connection
  7. CURLINFO_PRETRANSFER_TIME - Time in seconds from start until just before file transfer begins
  8. CURLINFO_STARTTRANSFER_TIME - Time in seconds until the first byte is about to be transferred
  9. CURLINFO_REDIRECT_COUNT - Number of redirects, with the CURLOPT_FOLLOWLOCATION option enabled
  10. CURLINFO_REDIRECT_TIME - Time in seconds of all redirection steps before final transaction was started, with the CURLOPT_FOLLOWLOCATION option enabled
  11. CURLINFO_REDIRECT_URL - With the CURLOPT_FOLLOWLOCATION option disabled: redirect URL found in the last transaction, that should be requested manually next. With the CURLOPT_FOLLOWLOCATION option enabled: this is empty. The redirect URL in this case is available in CURLINFO_EFFECTIVE_URL
  12. CURLINFO_PRIMARY_IP - IP address of the most recent connection
  13. CURLINFO_PRIMARY_PORT - Destination port of the most recent connection
  14. CURLINFO_LOCAL_IP - Local (source) IP address of the most recent connection
  15. CURLINFO_LOCAL_PORT - Local (source) port of the most recent connection
  16. CURLINFO_SIZE_UPLOAD - Total number of bytes uploaded
  17. CURLINFO_SIZE_DOWNLOAD - Total number of bytes downloaded
  18. CURLINFO_SPEED_DOWNLOAD - Average download speed
  19. CURLINFO_SPEED_UPLOAD - Average upload speed
  20. CURLINFO_HEADER_SIZE - Total size of all headers received
  21. CURLINFO_HEADER_OUT - The request string sent. For this to work, add the CURLINFO_HEADER_OUT option to the handle by calling setopt()
  22. CURLINFO_REQUEST_SIZE - Total size of issued requests, currently only for HTTP requests
  23. CURLINFO_SSL_VERIFYRESULT - Result of SSL certification verification requested by setting CURLOPT_SSL_VERIFYPEER
  24. CURLINFO_CONTENT_LENGTH_DOWNLOAD - content-length of download, read from Content-Length: field
  25. CURLINFO_CONTENT_LENGTH_UPLOAD - Specified size of upload
  26. CURLINFO_CONTENT_TYPE - Content-Type: of the requested document, NULL indicates server did not send valid Content-Type: header
  27. CURLINFO_PRIVATE - Private data associated with this cURL handle, previously set with the CURLOPT_PRIVATE option of setopt()

Returns

mixed|array|boolean —

If opt is given, returns it's value. Otherwise, returns an associative array with the following elements(which correspond to opt), or FALSE on failiure:

  • "url"
  • "content_type"
  • "http_code"
  • "header_size"
  • "request_size"
  • "filetime"
  • "ssl_verify_result"
  • "redirect_count"
  • "total_time"
  • "namelookup_time"
  • "connect_time"
  • "pretransfer_time"
  • "size_upload"
  • "size_download"
  • "speed_download"
  • "speed_upload"
  • "download_content_length"
  • "upload_content_length"
  • "starttransfer_time"
  • "redirect_time"
  • "certinfo"
  • "primary_ip"
  • "primary_port"
  • "local_ip"
  • "local_port"
  • "redirect_url"
  • "request_header" (This is only set if the CURLINFO_HEADER_OUT is set by a previous call to setopt())

pause()

pause(integer  $bitmask) : integer

Pause and unpause a connection

Parameters

integer $bitmask

One of the CURLPAUSE_* constants

Returns

integer —

Returns an error code (CURLE_OK for no error)

setopt_array()

setopt_array(array  $options) : boolean

Set multiple options for a cURL transfer

Parameters

array $options

An array specifying which options to set and their values. The keys should be valid curl_setopt() constants or their integer equivalents.

Returns

boolean —

Returns TRUE if all options were successfully set. If an option could not be successfully set, FALSE is immediately returned, ignoring any future options in the $options array.

setopt()

setopt(integer  $option, mixed  $value) : boolean

Set an option for a cURL transfer

Parameters

integer $option

The CURLOPT_XXX

mixed $value

The value to be set on option

Returns

boolean —

Returns TRUE on success or FALSE on failure.

unescape()

unescape(string  $str) : string

Decodes the given URL encoded string

Parameters

string $str

The URL encoded string to be decoded

Returns

string —

Returned decoded string or FALSE on failiure

reset()

reset() 

Reset all options of a libcurl session handle

headers_to_array()

headers_to_array(string  $headerContent) : array

Converts a string containing multiple headers into an array that can be used programatically.

Parameters

string $headerContent

A header string

Returns

array —

An indexable array of headers