Public Member Functions

cURL Class Reference

Object-oriented wrapper on default PHP cURL functions. More...

Public Member Functions

 __construct (array $settings=array())
 Create new object instance.
 init ($url, $options=FALSE)
 Add a new cURL session.
 set_option ($option, $value, $key=0)
 Set an option for a cURL transfer.
 set_options (array $options, $key=0)
 Set multiple options for a cURL transfer.
 exec ($key=FALSE)
 Perform a queued cURL transfers.
 errors ($key=FALSE)
 Return error number and it's description.
 info ($key=FALSE, $option=FALSE)
 Get information regarding a specific transfer number.
 close ($key=FALSE)
 Close session.
 clear ()
 Close all the sessions invoked with this object.
 __destruct ()
 Destroy object.

Detailed Description

Information

Version:
0.1
Author:
inst, http://www.inst.tk/
Date:
2011

Constructor & Destructor Documentation

cURL::__construct ( array $  settings = array())

While creating an instance of object of this class it will automaticaly check that needed cURL extension isn't availible on hosting and if so then will throw a cURLException.

Parameters:
settings(optional) An associative array of default values. It's used to initialize every session. Every record in this array must be in format where the key is one of default CURLOPT_XXX constants and the value is proper value for this constant. The exception is a parameters applied to whole class instance not every separate session. They can't be reinitiated later. For now it's the only one parameter:

  • retry: indicates how many tries should cURL do before returning a server error.
See also:
set_options()
cURL::__destruct ( )

Here is the benefits of object-oriented programing begins: now we have no need to remember what sessions we have initialized, because they will be closed automaticaly on object destroying.


Member Function Documentation

cURL::clear ( )

Destroys all sessions if there were any by closing them.

cURL::close ( key = FALSE)

Closes one session if first parameter given or works like clear() otherwise.

Parameters:
key(optional) Number of session handle. If not passed, all sessions will be closed.
cURL::errors ( key = FALSE)
Parameters:
key(optional) Number of cURL handle.
Returns:
If key is given, returns array with keys num and err that are equivalent to descibed below. If session performed succesfuly then num will be 0 (zero) and err will be just an empty string. If key is not specified, returns multidimensional array in format
  • result[handle_number]['num']: Internal number of cURL error.
  • result[handle_number]['err']: Clear text error message.
See also:
http://curl.haxx.se/libcurl/c/libcurl-errors.html For possible error codes.
cURL::exec ( key = FALSE)

Executes the given cURL session. This function should be called after initializing all cURL sessions and all the options for the sessions are set. When key is not specified, if more than one session were initialized performs multithreaded execution. Should throw RuntimeException if some errors occured while multithreaded execution.

Parameters:
key(optional) Number of session handle. Usualy there is no need to use it.
Returns:
Returns TRUE on success or FALSE on failure. However, if the CURLOPT_RETURNTRANSFER option is set, it will return the result (or the array of results) on success, FALSE on failure.
cURL::info ( key = FALSE,
option = FALSE 
)

Gets information about the last transfer in session with specified key.

Parameters:
key(optional) A number of a cURL handle.
option(optional) An option to check for.
Returns:
If both parameters are specified, returns string value of an option for session with number key. If only first parameter assigned then returns an associative array with the informational elements. If none parameters given, returns multidimensional array which as the first dimension contains a number of handle and the second is associative array of informational elements for that session.
See also:
http://www.php.net/curl_getinfo
cURL::init ( url,
options = FALSE 
)

Creates first cURL session or adds a new one to already exsisted queue. You can pass array as first parameter to initiate few sessions at once and every session will be associated with options specified by second parameter.

Parameters:
urlA string containing URL to be proceed or an array of strings. If you pass to it array and some records in the middle of it will be wrong then they and the records followed after they wouldn't be initialized.
options(optional) An associative array containing options of session or sessions (in case of array passed first parameter) to be created. It has higher priority and so will replace duplicate parameters from constructor.
Returns:
Returns boolean FALSE, if session or sessions initiation failed. Otherwise returns TRUE.
cURL::set_option ( option,
value,
key = 0 
)

Sets an option on the given cURL session handle.

Parameters:
optionThe CURLOPT_XXX option to set.
valueThe value to be set on option.
key(optional) Number of session handle. In normal flow there is no need to use it.
Returns:
Returns TRUE on success or FALSE on failure.
See also:
http://www.php.net/curl_setopt
cURL::set_options ( array $  options,
key = 0 
)

Sets multiple options for a cURL session. This function is useful for setting a large amount of cURL options without repetitively calling set_option(). May throw DomainException.

Parameters:
optionsAn array specifying which options to set and their values. The keys should be valid curl_setopt() constants or their integer equivalents.
key(optional) Number of session handle. In normal flow there is no need to use it.
Returns:
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.
See also:
http://www.php.net/curl_setopt_array

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