-
Notifications
You must be signed in to change notification settings - Fork 0
CurlMultiHandler :: setOption(constant, value)
Brian Boll edited this page Apr 23, 2018
·
7 revisions
Some of the behavior to be aware of when setting options on handles is illustrated by this example:
//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 user agent option for all currently added handles: $ch1, $ch2
$mch->setOption(CURLOPT_USERAGENT, 'EXAMPLE_USERAGENT');
//Changes the URL for one handle: $ch2
$ch2->setOption(CURLOPT_URL, 'https://github.com');
//Changes the URL for both currently added handles: $ch1, $ch2
$mch->setOption(CURLOPT_URL, 'this_is_not_a_valid_URL');
//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 set
[1] constant: A constant representing one of the libcurl options detailed more here
[2] value: The expected value for the corresponding option passed by the first parameter
No return value