thesis / grpc-deadline
Client-side deadline interceptor (grpc-timeout + local cancellation) for thesis/grpc.
Fund package maintenance!
0.1.0
2026-08-03 17:20 UTC
Requires
- php: ^8.4
- amphp/amp: ^3.1
- thesis/grpc-client: ^0.2
- thesis/grpc-protocol: ^0.2.1
Requires (Dev)
- symfony/var-dumper: ^8.0
- testo/assert: ^0.1.11
- testo/test: ^0.1.6
- testo/testo: ^0.10.29
README
Client-side deadline interceptor for thesis/grpc. It gives every outgoing call a deadline and applies it in two places so the client and server agree on it:
- the
grpc-timeoutheader, which the server enforces (cancelling the RPC and returningDEADLINE_EXCEEDED); - a local
TimeoutCancellation, so the client gives up on its own even if the server never responds (a plain client deadline otherwise never reaches the server — the transport does not setgrpc-timeoutby itself).
Contents
Installation
composer require thesis/grpc-deadline
Usage
Register the interceptor on the client's unary and stream chains. A default deadline covers every call:
use Thesis\Grpc\Client; use Thesis\Grpc\Deadline; use Thesis\Grpc\Metadata\Timeout; $deadline = new Deadline\ClientInterceptor(Timeout::seconds(30)); $client = new Client\Builder() ->withUnaryInterceptors($deadline) ->withStreamInterceptors($deadline) ->build();
Override it per call by attaching a Timeout to the call's metadata — the call's own deadline wins
over the default:
use Thesis\Grpc\Metadata; use Thesis\Grpc\Metadata\Timeout; $client->invoke($request, $invoke, new Metadata()->withKey(Timeout::milliseconds(200)));
Constructed with no default (new Deadline\ClientInterceptor()), the interceptor only acts on calls
that carry their own grpc-timeout, and leaves the rest untouched.