(PECL yar >= 1.0.0)
Yar_Concurrent_Client::loop — Send and wait for all registered calls
$callback = null, ?callable $error_callback = null, ?array $options = null): ?boolSends all calls registered with Yar_Concurrent_Client::call() in parallel and blocks until every response has arrived and been handled. The call list is emptied when this method returns.
callback
A callable used to handle responses for calls that were
registered without their own callback. Right after all requests have
been sent, it is additionally called once with two null arguments,
before any response arrives.
error_callback
A callable used to handle errors for calls that were
registered without their own error callback. It receives three
arguments: the error type (one of the YAR_ERR_*
codes), the error message, and the callinfo
array.
options
An array of client options, keyed by the
YAR_OPT_* constants, applied to every registered
call that does not override them.
Returns true when every registered call has been handled, or when no
calls have been registered at all. Returns false if the concurrent
client is already running inside another loop; in that case a warning is
raised.
Example #1 Yar_Concurrent_Client::loop() example
<?php
function callback($retval, $callinfo) {
if ($callinfo == NULL) {
echo "Now, all requests are sent, and no 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");
/* if the callback is not specified, the callback of loop() will be used */
Yar_Concurrent_Client::call("http://host/api/", "some_method", array("parameters"));
Yar_Concurrent_Client::loop("callback", "error_callback");
?>The above example will output something similar to:
Now, all requests are sent, and no response available This is a remote call response, the method name is some_method. calling sequence is 2 string(11) "some_method" This is a remote call response, the method name is some_method. calling sequence is 1 string(11) "some_method"