FUEL CMS User Guide : Version 1.3.2


Curl Class

Some code borrowed from: http://semlabs.co.uk/journal/object-oriented-curl-class-with-multi-threading.

Properties Reference

Property Default Value Description
public
user_agent CCBot/2.0 (http://commoncrawl.org/faq/) The user agent CURL should use
timeout 10 The maximum number of seconds to allow cURL functions to execute.
connect_timeout 10 The number of seconds to wait while trying to connect. Use 0 to wait indefinitely.
dns_cache_timeout 3600 The number of seconds to keep DNS entries in memory. This option is set to 120 (2 minutes) by default.
cookie_file /var/www/vhosts/getfuelcms.com/subdomains/docs/httpdocs/fuel/application/cache/my_cookie.txt The name to be used for the cookie file
block_size 5 The number of CURL sessions to executed simultaneously
protected
CI N/A
_sessions N/A CURL sessions
_info N/A
_error N/A
_output N/A

Function Reference [+]

$this->curl->initialize([$params=array()])

Initialize the object and set object parameters. Accepts an associative array as input, containing object preferences. Also will set the values in the parameters array as properties of this object.

Returns

void

Parameters

(array) $params config preferences

$this->curl->set_params($params)

Set object parameters.

Returns

void

Parameters

(array) $params config preferences

$this->curl->add_session('$url', [$opts=array()], [$opt_params=array()])

Adds a CURL session.

Returns

void

Parameters

(string) $url The URL to use for the CURL session
(array) $opts An array of CURL options (http://www.php.net/manual/en/function.curl-setopt.php). Can be short syntax of 'get', 'post', 'head', 'none 'cookie' (optional)
(array) $opt_params An array of additional options you can pass to your request. In particular $_POST or $_COOKIE parameters (optional)

$this->curl->set_option('$opt', '$val', ['$key'=0])

Adds a CURL option to a particular session.

Returns

void

Parameters

(string) $opt The CURL option (http://www.php.net/manual/en/function.curl-setopt.php)
(mixed) $val The CURL value for the option
(int) $key The key value of a CURL session (optional)

$this->curl->set_options($opts, ['$key'=0])

Adds CURL options to a particular session.

Returns

void

Parameters

(array) $opts An array of CURL options (http://www.php.net/manual/en/function.curl-setopt.php).
(int) $key The key value of a CURL session (optional)

$this->curl->exec(['$key'=FALSE], ['$clear'=TRUE])

Executes either a single or multiple CURL session.

Returns

string

Parameters

(string) $key The key value of a CURL session. If none provided, it will execute all sessions in the stack (optional)
(boolean) $clear Wether to clear out the sessions after execution. Default is TRUE (optional)

$this->curl->exec_single(['$key'=0], ['$clear'=TRUE])

Executes a single.

Returns

string

Parameters

(int) $key The key value of a CURL session. If none provided, it will execute all sessions in the stack (optional)
(boolean) $clear Wether to clear out the sessions after execution. Default is TRUE (optional)

$this->curl->exec_multi(['$clear'=TRUE], ['$block_size'=NULL])

Executes multiple sessions at once. Can be more efficient when doing a lot of CURL requests at once.

Returns

string

Parameters

(boolean) $clear Wether to clear out the sessions after execution. Default is TRUE (optional)
(int) $block_size The number to execute simultaneously. Default is 5 (optional)

$this->curl->is_multi()

Determines if their are multiple sessions in the stack to execute.

Returns

boolean

$this->curl->info(['$opt'=NULL], ['$key'=0])

Returns information of an executed session.

Returns

mixed

Parameters

(string) $opt The name of the parameter to return. If no value is proviced, then all values will be returned (optional)
(mixed) $key The key value of a CURL session. If set to TRUE, then it will return all the infos from a mult-session (optional)

$this->curl->sessions(['$key'=FALSE])

Returns an array of CURL resource objects.

Returns

array

Parameters

(int) $key The key value of a CURL session (optional)

$this->curl->output(['$key'=FALSE])

Returns the output of an executed CURL session. If multiple sessions are executed, the output will be in an array.

Returns

mixed

Parameters

(int) $key The key value of a CURL session (optional)

$this->curl->close(['$key'=FALSE])

Closes CURL session(s). If multiple sessions were executed, and no key is provided, all sessions will be closed.

Returns

void

Parameters

(int) $key The key value of a CURL session (optional)

$this->curl->clear(['$key'=FALSE])

Clears CURL session(s) from the stack. If multiple sessions were executed, and no key is provided, all sessions will be cleared.

Returns

void

Parameters

(int) $key The key value of a CURL session (optional)

$this->curl->get('$url')

Shorthand for a simple GET CURL request.

Returns

string

Parameters

(string) $url The URL to use for the CURL session

$this->curl->post('$url', [$post=array()])

Shorthand for a simple POST CURL request.

Returns

string

Parameters

(string) $url The URL to use for the CURL session
(array) $post An array of $_POST parameter to pass to the URL (optional)

$this->curl->head('$url')

Shorthand for a simple HEAD CURL request.

Returns

string

Parameters

(string) $url The URL to use for the CURL session

Shorthand for a simple POST CURL request.

Returns

string

Parameters

(string) $url The URL to use for the CURL session
(array) $cookie An array of parameter to set on the cookie
(boolean) $cleanup Whether to cleanup the cookie crumbs left behind (optional)

$this->curl->error(['$key'=FALSE])

Returns error(s) from the CURL request.

Returns

mixed

Parameters

(string) $key An index value of an error message (optional)

$this->curl->has_error(['$key'=FALSE])

Returns TRUE if there are errors detected and FALSE if not.

Returns

boolean

Parameters

(string) $key An index value of an error message (optional)

$this->curl->is_valid('$url')

Shorthand for a simple POST CURL request.

Returns

void

Parameters

(string) $url The URL to use for the CURL session

$this->curl->is_enabled()

Determines whether or not CURL can run based on the system's settings.

Returns

boolean