PHP 8.6.0 Beta 3 is available for testing

Yar_Client::setOpt

(PECL yar >= 1.0.0)

Yar_Client::setOptSet client options

説明

public function Yar_Client::setOpt(int $name, mixed $value): Yar_Client|bool

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, msgpack
  • YAR_OPT_PERSISTENT — a boolean persistent-connection flag (HTTP keep-alive)
  • YAR_OPT_TIMEOUT — a timeout in milliseconds, overriding yar.timeout
  • YAR_OPT_CONNECT_TIMEOUT — a connect timeout in milliseconds, overriding yar.connect_timeout
  • YAR_OPT_HEADER (as of 2.0.4) — an array of additional HTTP header lines
  • YAR_OPT_RESOLVE (as of 2.1.0) — an array of hostname resolution entries
  • YAR_OPT_PROXY (as of 2.2.0) — an HTTP proxy address
  • YAR_OPT_PROVIDER (as of 2.3.0) — the provider identity, up to 32 bytes
  • YAR_OPT_TOKEN (as of 2.3.0) — the authentication token, up to 32 bytes
value

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");
?>

参考

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top