(PECL yar >= 1.0.0)
Yar_Concurrent_Client::loop — 发送所有调用
$callback
= ?, callable $error_callback
= ?): bool发送所有已注册的远程 RPC 调用。
callback
如果设置了此回调,则 Yar 将在所有调用发送且任何响应返回之前调用此回调,并使用 $callinfo NULL。
然后,如果用户在注册并发调用时未指定回调,则此回调将用于处理响应,否则将使用注册时指定的回调。
error_callback
如果设置了此回调,则 Yar 将在发生错误时调用此回调。
示例 #1 Yar_Concurrent_Client::loop() 示例
<?php
function callback($retval, $callinfo) {
if ($callinfo == NULL) {
echo "现在,所有请求都已发送,并且没有任何响应可用\n";
} else {
echo "这是一个远程调用响应,方法名称是", $callinfo["method"],
". 调用序列是 " , $callinfo["sequence"] , "\n";
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")); // 如果未指定回调,
// 循环中的回调将被使用
Yar_Concurrent_Client::call("http://host/api/", "some_method", array("parameters"), "callback", NULL, array(YAR_OPT_PACKAGER => "json"));
// 此服务器接受 json 封装器
Yar_Concurrent_Client::call("http://host/api/", "some_method", array("parameters"), "callback", NULL, array(YAR_OPT_TIMEOUT=>1));
// 自定义超时
Yar_Concurrent_Client::loop("callback", "error_callback"); // 发送请求,
// error_callback 可选
?>
以上示例将输出类似以下内容
Now, all requests are sent, and no any response available This is a remote call response, the method name issome_method. calling sequence is 4 string(11) "some_method" This is a remote call response, the method name issome_method. calling sequence is 1 string(11) "some_method" This is a remote call response, the method name issome_method. calling sequence is 2 string(11) "some_method" This is a remote call response, the method name issome_method. calling sequence is 3 string(11) "some_method"