Yar_Client::setOpt
(PECL yar >= 1.0.0)
Set client options
Description
Sets an option on the client. Options are evaluated when a call is issued, so they can be changed between calls.
Parameters
nameOne of the
YAR_OPT_*constants:YAR_OPT_PACKAGER— a packager name:php,jsonor, when built with msgpack support,msgpackYAR_OPT_PERSISTENT— a boolean persistent-connection flag (HTTP keep-alive)YAR_OPT_TIMEOUT— a timeout in milliseconds, overriding yar.timeoutYAR_OPT_CONNECT_TIMEOUT— a connect timeout in milliseconds, overriding yar.connect_timeoutYAR_OPT_HEADER(as of 2.0.4) — an Array of additional HTTP header linesYAR_OPT_RESOLVE(as of 2.1.0) — an Array of hostname resolution entriesYAR_OPT_PROXY(as of 2.2.0) — an HTTP proxy addressYAR_OPT_PROVIDER(as of 2.3.0) — the provider identity, up to 32 bytesYAR_OPT_TOKEN(as of 2.3.0) — the authentication token, up to 32 bytes
valueThe option value. An invalid value raises a warning and makes the call return false.
Return Values
Returns the client object itself, allowing a fluent interface, or false when the option name is unknown, the value is invalid, or the option does not apply to the protocol the client was created with.
Errors/Exceptions
Conditions that make the call return false also raise a warning:
YAR_OPT_HEADER,YAR_OPT_RESOLVEandYAR_OPT_PROXYonly work with the HTTP protocol; using them with atcp://orunix://client raises a warning.YAR_OPT_RESOLVEadditionally requires libcurl >= 7.21.3.- Each option expects a specific value type (string, boolean, integer or array), described on the constants page.
Examples
Yar_Client::setOpt example
<?php
$client = new Yar_Client("http://api.example.com/operator.php");
/* Set timeout to 1s */
$client->setOpt(YAR_OPT_TIMEOUT, 1000);
/* Set packager to JSON */
$client->setOpt(YAR_OPT_PACKAGER, "json");
/* Set custom headers */
$client->setOpt(YAR_OPT_HEADER, ["X-Api-Key: value"]);
/* Route through an HTTP proxy */
$client->setOpt(YAR_OPT_PROXY, "127.0.0.1:8888");
/* call remote service */
$result = $client->some_method("parameter");
?>See Also
Yar_Client::getOptYar_Client::call