Yar_Concurrent_Client::call
(PECL yar >= 1.0.0)
Yar_Concurrent_Client::call — 注册一个并行的服务调用
说明
   public static Yar_Concurrent_Client::call(
string
string
array
callable
callable
array
): int
  string
$uri,string
$method,array
$parameters = ?,callable
$callback = ?,callable
$error_callback = ?,array
$options = ?): int
注册一个并行的(异步的)远程服务调用, 不过这个调用请求不会被立即发出, 而是会在接下来调用 Yar_Concurrent_Client::loop()的时候才真正的发送出去.
参数
uri- 
     
RPC 服务的 URI(http 或 tcp).
 method- 
     
调用的服务名字(也就是服务方法名).
 parameters- 
     
调用的参数.
 callback- 
     
回调函数, 在远程服务的返回到达的时候被Yar调用, 从而可以处理返回内容.
 
返回值
唯一 ID, 可用于区分到底是那个调用的返回.
示例
示例 #1 Yar_Concurrent_Client::call()示例
<?php
function callback($retval, $callinfo) {
var_dump($retval);
}
function error_callback($type, $error, $callinfo) {
error_log($error);
}
Yar_Concurrent_Client::call("http://host/api/", "some_method", array("parameters"), "callback");
Yar_Concurrent_Client::call("http://host/api/", "some_method", array("parameters"));   // if the callback is not specificed, 
                                                                               // callback in loop will be used
Yar_Concurrent_Client::call("http://host/api/", "some_method", array("parameters"), "callback", NULL, array(YAR_OPT_PACKAGER => "json"));
//this server accept json packager
Yar_Concurrent_Client::call("http://host/api/", "some_method", array("parameters"), "callback", NULL, array(YAR_OPT_TIMEOUT=>1));
//custom timeout 
// 这个时候请求都还没有发出
?>以上示例的输出类似于:
参见
- Yar_Concurrent_Client::loop() - 发送所有注册的并行调用
 - Yar_Concurrent_Client::reset() - Clean all registered calls
 - Yar_Server::__construct() - 注册 HTTP RPC Server
 - Yar_Server::handle() - 启动HTTP RPC Server
 
  +添加备注
  
 用户贡献的备注
此页面尚无用户贡献的备注。
备份地址:http://www.lvesu.com/blog/php/yar-concurrent-client.call.php