Skip to content

CurlMultiHandler :: setOptions(array)

Brian Boll edited this page Apr 23, 2018 · 3 revisions

CurlMultiHandler :: setOptions(array)

$options = array(
    CURLOPT_URL => "this_is_not_a_valid_URL",
    CURLOPT_USERAGENT => "EXAMPLE_USERAGENT",
    CURLOPT_POST => false,
    CURLOPT_RETURNTRANSFER => true
);

//Construct the multi handler object
$mch = new CurlMultiHandler();

//Construct various handles to be handled by the multi handler object
$ch1 = new CurlHandler('http://example.com');
$ch2 = new CurlHandler('http://google.com');
$ch3 = new CurlHandler('http://google.com');

//Add the first two handles
$mch->addHandle($ch1);
$mch->addHandle($ch2);

//Sets options (including URL change) for currently added handles: $ch1, $ch2
$mch->setOptions($options);

//None of the above options apply to this handle since it was added after
$mch->addHandle($ch3);

$mch->execute();

var_dump($mch->getError());

The $ch1 and $ch2 handles will both return errors "Couldn't resolve host name" on URL "this_is_not_a_valid_URL".

$ch3 should return success (0) on URL "http://google.com".

Note: $ch3 request will not have a user agent, post or return transfer set

Parameters [1]:

[1] array: An array containing constants as keys each representing one of the libcurl options detailed more here and their corresponding expected values

Returns:

No return value

Clone this wiki locally