Documentation

CoopExecutor
in package
implements ExecutorInterface

FinalYes

Cooperatively resolves hosts via the given base executor to ensure same query is not run concurrently

Wraps an existing ExecutorInterface to keep tracking of pending queries and only starts a new query when the same query is not already pending. Once the underlying query is fulfilled/rejected, it will forward its value to all promises awaiting the same query.

This means it will not limit concurrency for queries that differ, for example when sending many queries for different host names or types.

This is useful because all executors are entirely async and as such allow you to execute any number of queries concurrently. You should probably limit the number of concurrent queries in your application or you're very likely going to face rate limitations and bans on the resolver end. For many common applications, you may want to avoid sending the same query multiple times when the first one is still pending, so you will likely want to use this in combination with some other executor like this:

$executor = new CoopExecutor(
    new RetryExecutor(
        new TimeoutExecutor(
            new UdpTransportExecutor($nameserver),
            3.0
        )
    )
);

Table of Contents

Interfaces

ExecutorInterface

Properties

$counts  : mixed
$executor  : mixed
$pending  : mixed

Methods

__construct()  : mixed
query()  : PromiseInterface<string|int, Message>
Executes a query and will return a response message
serializeQueryToIdentity()  : mixed

Properties

Methods

query()

Executes a query and will return a response message

public query(Query $query) : PromiseInterface<string|int, Message>

It returns a Promise which either fulfills with a response React\Dns\Model\Message on success or rejects with an Exception if the query is not successful. A response message may indicate an error condition in its rcode, but this is considered a valid response message.

$executor->query($query)->then(
    function (React\Dns\Model\Message $response) {
        // response message successfully received
        var_dump($response->rcode, $response->answers);
    },
    function (Exception $error) {
        // failed to query due to $error
    }
);

The returned Promise MUST be implemented in such a way that it can be cancelled when it is still pending. Cancelling a pending promise MUST reject its value with an Exception. It SHOULD clean up any underlying resources and references as applicable.

$promise = $executor->query($query);

$promise->cancel();
Parameters
$query : Query
Return values
PromiseInterface<string|int, Message>

serializeQueryToIdentity()

private serializeQueryToIdentity(Query $query) : mixed
Parameters
$query : Query

        
On this page

Search results