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:

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:

Приклади

Приклад #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