(PECL yar >= 1.0.0)
Yar_Concurrent_Client::call — Register a concurrent call
$uri,$method,$parameters = null,$callback = null,$error_callback = null,$options = nullRegisters a remote RPC call. The request is not sent immediately; all registered calls are sent together by Yar_Concurrent_Client::loop(), and the responses are handled as they arrive.
Note:
Only HTTP and HTTPS URIs are supported. TCP and Unix socket transports are not available for concurrent calls.
uri
Address of the RPC service, starting with
http:// or https://.
methodThe name of the remote service method.
parametersThe list of arguments passed to the remote method.
callback
A callable invoked when the response for this call
arrives, with two arguments: the response value, and a
callinfo array with the keys
sequence, uri and
method. If omitted, the
callback of
Yar_Concurrent_Client::loop() is used.
error_callback
A callable invoked when this call fails, with three
arguments: the error type (one of the YAR_ERR_*
codes), the error message, and the callinfo
array. If omitted, the error_callback of
Yar_Concurrent_Client::loop() is used.
options
An array of client options, keyed by the
YAR_OPT_* constants, see
Yar_Client::setOpt(). Applied to this call
only.
Returns the sequence number of the registered call, a unique ID
starting from 1 that identifies the call. Returns
false when the concurrent client is already inside
Yar_Concurrent_Client::loop() or when the maximum
of 128 registered calls is reached; in both cases a
warning is raised. Returns null if the URI or method name is empty, or
the URI is not an HTTP(S) address, with a warning.
<?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");
/* If the callback is not specified, the callback of loop() will be used */
Yar_Concurrent_Client::call("http://host/api/", "some_method", array("parameters"));
/* This server accepts the JSON packager */
Yar_Concurrent_Client::call("http://host/api/", "some_method", array("parameters"), "callback", NULL, array(YAR_OPT_PACKAGER => "json"));
/* Custom timeout */
Yar_Concurrent_Client::call("http://host/api/", "some_method", array("parameters"), "callback", NULL, array(YAR_OPT_TIMEOUT => 1000));
/* The requests are not sent yet */