Yar Yar_Concurrent_Client::loop
(PECL yar >= 1.0.0)
Yar_Concurrent_Client::loop — Send all calls
설명
public static Yar_Concurrent_Client::loop(callable $callback
= ?, callable $error_callback
= ?): bool
등록된 모든 원격 RPC 호출을 보냅니다.
매개변수
callback
- 이 콜백이 설정되면 Yar는 모든 호출이 전송된 후 응답이 반환되기 전에 $callinfo NULL과 함께 이 콜백을 호출합니다.
그런 다음 동시 호출 등록 시 사용자가 콜백을 지정하지 않은 경우 이 콜백을 사용하여 응답을 처리하고, 그렇지 않으면 등록 시 지정한 콜백을 사용합니다.
error_callback
- 이 콜백이 설정되면 Yar는 오류가 발생한 동안 이 콜백을 호출합니다.
반환 값
Examples
예제 #1 Yar_Concurrent_Client::loop() 예제
<?php
function callback($retval, $callinfo) {
if ($callinfo == NULL) {
echo "Now, all requests are sent, and no any response available\n";
} else {
echo "This is a remote call response, the method name is", $callinfo["method"],
". calling sequence is " , $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")); // 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("callback", "error_callback"); //send the requests,
//the error_callback is optional
?>
위의 예는 다음과 유사한 결과를 출력합니다.
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"
기타
- Yar_Concurrent_Client::call() - Register a concurrent call
- Yar_Concurrent_Client::reset() - Clean all registered calls
- Yar_Server::__construct() - Register a server
- Yar_Server::handle() - Start RPC Server