PHP 8.6.0 Beta 3 is available for testing

Yar_Concurrent_Client::call

(PECL yar >= 1.0.0)

Yar_Concurrent_Client::callRegister a concurrent call

Descrizione

public static function Yar_Concurrent_Client::call(
    string $uri,
    string $method,
    ?array $parameters = null,
    ?callable $callback = null,
    ?callable $error_callback = null,
    ?array $options = null
): int|false|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.

Nota:

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.

Elenco dei parametri

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.

Valori restituiti

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.

Esempi

<?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 */

Vedere anche:

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top