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_PACKAGER、 YAR_OPT_PERSISTENT(需要服务端支持 keepalive)、 YAR_OPT_TIMEOUT、 YAR_OPT_CONNECT_TIMEOUT、 YAR_OPT_HEADER(自 2.0.4 起)

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

/* 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