PHP 8.5.10 Released!

Yar_Concurrent_Client::call

(PECL yar >= 1.0.0)

Yar_Concurrent_Client::callRegister a concurrent call

Description

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.

Note:

Only HTTP and HTTPS URIs are supported. TCP and Unix socket transports are not available for concurrent calls.

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 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.

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

See Also

add a note

User Contributed Notes

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