(PECL yar >= 1.0.0)
Yar_Concurrent_Client::loop — Send all calls
Send all registed remote RPC calls.
callback
If this callback is set, then Yar will call this callback after all calls are sent and before any response return, with a $callinfo NULL.
Then, if user didn't specify callback when registering concurrent call, this callback will be used to handle response, otherwise, the callback specified while registering will be used.
error_callback
If this callback is set, then Yar will call this callback while error occurred.
Exemplo #1 Yar_Concurrent_Client::loop() example
<?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,
O exemplo acima produzirá algo semelhante a:
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"