Yar_Concurrent_Client::call
(PECL yar >= 1.0.0)
Register a concurrent call
Description
Registers 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.
Only HTTP and HTTPS URIs are supported. Concurrent calls are sent simultaneously using curl's multi-handle interface, and the TCP/Unix socket transport does not provide this facility.
Parameters
uriAddress of the RPC service, starting with
http://orhttps://.methodThe name of the remote service method.
parametersThe list of arguments passed to the remote method.
callbackA
callableinvoked when the response for this call arrives, with two arguments: the response value, and acallinfoArray describing the call:sequence— the sequence number returned when the call was registereduri— the address of the servicemethod— the name of the remote method
If omitted, the
callbackofYar_Concurrent_Client::loopis used; see that method for what happens when neither is given.error_callbackA
callableinvoked when this call fails, with three arguments: the error type (one of theYAR_ERR_*codes), the error message, and thecallinfoArray described above. If omitted, theerror_callbackofYar_Concurrent_Client::loopis used; see that method for what happens when neither is given.optionsAn Array of client options, keyed by the
YAR_OPT_*constants, seeYar_Client::setOpt. Applied to this call only.
Return Values
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.
Examples
<?php
function callback($retval, $callinfo)
{
var_dump($retval);
}
function error_callback($type, $error, $callinfo)
{
error_log($error);
}
Yar_Concurrent_Client::call("http://api.example.com/operator.php", "some_method", array("parameters"), "callback");
/* If the callback is not specified, the callback of loop() will be used */
Yar_Concurrent_Client::call("http://api.example.com/operator.php", "some_method", array("parameters"));
/* This server accepts the JSON packager */
Yar_Concurrent_Client::call("http://api.example.com/operator.php", "some_method", array("parameters"), "callback", NULL, array(YAR_OPT_PACKAGER => "json"));
/* Custom timeout */
Yar_Concurrent_Client::call("http://api.example.com/operator.php", "some_method", array("parameters"), "callback", NULL, array(YAR_OPT_TIMEOUT => 1000));
/* The requests are not sent yet */See Also
Yar_Concurrent_Client::loopYar_Concurrent_Client::reset