Yar_Client::setOpt

(PECL yar >= 1.0.0)

Yar_Client::setOpt设置调用的配置

说明

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

设置调用远程服务的一些配置,比如超时值、打包类型等。

参数

name

可以是: YAR_OPT_PACKAGERYAR_OPT_PERSISTENT(需要服务端支持)、 YAR_OPT_TIMEOUTYAR_OPT_CONNECT_TIMEOUTYAR_OPT_HEADER(自 2.0.4 起)、 YAR_OPT_PROXY(自 2.2.0 起)

value

返回值

成功时返回 $this 或者在失败时返回 false

示例

示例 #1 Yar_Client::setOpt() 示例

<?php

$cient
= new Yar_Client("http://host/api/");

//Set timeout to 1s
$client->SetOpt(YAR_OPT_CONNECT_TIMEOUT, 1000);

//Set packager to JSON
$client->SetOpt(YAR_OPT_PACKAGER, "json");

//Set Custom headers
$client->SetOpt(YAR_OPT_HEADER, array("hr1: val1", "hd2: val2"));

// Set Http Proxy
$client->SetOpt(YAR_OPT_PROXY, "127.0.0.1:8888");

/* call remote service */
$result = $client->some_method("parameter");
?>

以上示例的输出类似于:


参见

add a note add a note

User Contributed Notes

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