Yar_Concurrent_Client::call

Register a concurrent call

Description

public static intfalsenull Yar_Concurrent_Client::call(
    string $uri,
    string $method,
    arraynull $parameters = null,
    callablenull $callback = null,
    callablenull $error_callback = null,
    arraynull $options = null
)

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.

Note: 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

uri
Address of the RPC service, starting with http:// or https://.
method
The name of the remote service method.
parameters
The 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 describing the call:
  • sequence — the sequence number returned when the call was registered
  • uri — the address of the service
  • method — the name of the remote method
If omitted, the callback of Yar_Concurrent_Client::loop is used; see that method for what happens when neither is given.
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 described above. If omitted, the error_callback of Yar_Concurrent_Client::loop is used; see that method for what happens when neither is given.
options
An array of client options, keyed by the YAR_OPT_* constants, see Yar_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::loop
  • Yar_Concurrent_Client::reset