CakeFest 2024: The Official CakePHP Conference

Yar_Concurrent_Client::call

(PECL yar >= 1.0.0)

Yar_Concurrent_Client::call注册一个并行的服务调用

说明

public static Yar_Concurrent_Client::call(
    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

// 这个时候请求都还没有发出
?>

以上示例的输出类似于:


参见

add a note

User Contributed Notes

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