(PECL yar >= 1.0.0)
Yar_Client::setOpt — Set client options
Sets an option on the client. Options are evaluated when a call is issued, so they can be changed between calls.
name
One of the YAR_OPT_* constants:
YAR_OPT_PACKAGER — a packager name: php, json or, 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 bytesvalue
The option value. An invalid value raises a warning and makes the call
return false.
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.
Conditions that make the call return false also raise a warning:
YAR_OPT_HEADER,
YAR_OPT_RESOLVE and
YAR_OPT_PROXY only work with the HTTP protocol;
using them with a tcp:// or
unix:// client raises a warning.
YAR_OPT_RESOLVE additionally requires libcurl
>= 7.21.3.
Each option expects a specific value type (string, boolean, integer or array), described on the constants page.
Приклад #1 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");
?>