-
Notifications
You must be signed in to change notification settings - Fork 100
Chang Long Xu edited this page Sep 30, 2015
·
16 revisions
#Dora API Introduce
##Class Client ###function __construct() init the Client class 初始化class并传递连接配置
$config = array(
array("ip" => "127.0.0.1", "port" => 9567),
array("ip"=>"127.0.0.1","port"=>9567), //you can set more ,the client will random select one,to increase High availability
);
$client = \DoraRPC\Client($config);
- Client use a array for group of config.to improve the High availability.为了提高高可用 客户端使用一组配置。
- it's will random get a IP:Port. when you have't special it.实际使用过程中如果在调用的时候没有指定ip和端口,会随机从配置中找到配置使用。
- IP:Port will put into blacklist .when the connect fail on the thread 若发现配置连接失败则此配置会被列入黑名单,在此次调用中不会再次使用。
- Client will clean up the blacklist.when the config "use out" and try again.如果所有配置都被列入黑名单无配置可用,客户端会重新启用黑名单配置进行尝试。
###function singleAPI($name, $param, $sync = true, $retry = 0, $ip = "", $port = "") Call Remote one API,调用远程的一个api方法
$result = $obj->singleAPI("abc", array(234, $i), true, 1);
Parameter:
- $name(string): api name that you want invoke .要调用的api名字
- $param(array("key"=>value)):the parameter you want passed.要传递的参数
- $sync(bool):wait for the result?.是否阻塞等待处理结果
- $retry(int):when the connect fail.retry times。如果连接失败指定重试多少次
- $ip if it's empty the client will random find one on the init config.如果没有指定连接的ip,那么自动从配置选择一个配置。如果指定了则使用这个指定ip
- $port if it's empty the client will random find one on the init config.如果没有指定连接的port,那么自动从配置选一个。如果指定了则使用这个指定port
Result返回结果:
array(3) {
["code"]=> //communicate stat
int(0)
["msg"]=>
string(2) "OK"
["data"]=>
array(4) { //server respone info
["code"]=>
int(0)
["msg"]=>
string(2) "OK"
["data"]=>
array(1) {
["hehe"]=>
string(5) "ohyes"
}
["guid"]=>
string(32) "93151fa62cb441cd7efcb68158e671ea"
}
}
###multiAPI($params, $sync = true, $retry = 0, $ip = "", $port = "") Concurrent Call Multi Remote API,调用远程多个API并一起返回结果
$data = array(
"oak" => array("name" => "oakdf", "param" => array("dsaf" => "321321")),
"cd" => array("name" => "oakdfff", "param" => array("codo" => "fds")),
);
$ret = $obj->multiAPI($data, true, 1);
Parameter:
- $params(array): parameter && apiname array,result by parameter key.api名称和参数用数组方式传递,返回的结果会使用传入时的key做为key返回
- $sync(bool):waiting for result.是否等待处理结果
- $retry(int):retry time,when connect fail.连接失败重试多少次
- $ip if it's empty the client will random find one on the init config.如果没有指定连接的ip,那么自动从配置选择一个配置。如果指定了则使用这个指定ip
- $port if it's empty the client will random find one on the init config.如果没有指定连接的port,那么自动从配置选一个。如果指定了则使用这个指定port
Result:
array(3) {
["code"]=>
int(0)
["msg"]=>
string(2) "OK"
["data"]=>
array(4) {
["code"]=>
int(0)
["msg"]=>
string(2) "OK"
["data"]=>
array(2) {
["cd"]=>
array(1) {
["hehe"]=>
string(5) "ohyes"
}
["oak"]=>
array(1) {
["hehe"]=>
string(5) "ohyes"
}
}
["guid"]=>
string(32) "347dc1aa8f06ccf9db09b4b1c4340d83"
}
}